home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / V4 / tcw.z / getpoint.bas < prev    next >
Encoding:
BASIC Source File  |  1997-10-28  |  2.2 KB  |  84 lines

  1. 'Program that shows how to use TCWGetPoint, TCWVertexFindVertex
  2.  
  3. 'The program will create a dimension
  4. sub main()
  5. Dim v1 As Long
  6. Dim v2 As Long
  7. Dim v3 As Long
  8. Dim res as long
  9. Dim s as String
  10. Dim g As Long
  11. Dim vd As Long
  12. Dim e As String
  13. Dim dActive As Long
  14.     
  15.         ' Check for valid drawing
  16.     dActive = TCWDrawingActive ()
  17.         If dActive = 0 Then
  18.            MsgBox "Program requires active drawing. Open any drawing and try again."
  19.            ' Terminate the program
  20.            Stop
  21.         End If
  22.  
  23. 'Create three vertices with 0 XYZ values
  24. v1 = TCWVertexCreate(0,0,0) 
  25. v2 = TCWVertexCreate(0,0,0)
  26. v3 = TCWVertexCreate(0,0,0)
  27.  
  28. 'Get user to input first end point
  29. 'we are using snap mode SNAP_ANYPOINT, and a cross cursor
  30. res = tcwgetpoint(v1, "Dimension : First End Point", 0, 0, &h00FC, 2)
  31.  
  32. 'if success then continue
  33. if (res = 0) Then
  34.    ' snap to the nearest point
  35.    res = TCWVertexFindVertex(v1, &h00FC)
  36.  
  37.    ' create a line for dragging
  38.    g = TCWLineSingle(TCWGetX(v1), TCWGetY(v1), TCWGetZ(v1), _ 
  39.                      TCWGetX(v1), TCWGetY(v1), TCWGetZ(v1))
  40.  
  41.    ' flush the redraw que to force the above line to draw
  42.  
  43.    vd = TCWVertexAt(g, 1)
  44.  
  45.    res = TCWgetpoint(v2, "Dimension : Second End Point", g, vd, &h00FC, 2)
  46.  
  47.    ' remove the TCWLineSingle
  48.    TCWUndo 1
  49.  
  50.    if (res = 0) Then        
  51.       ' snap to the nearest point
  52.     res = TCWVertexFindVertex(v2, &h00FC)
  53.  
  54.       TCWSetXYZ v3, TCWGetX(v2), TCWGetY(v2), TCWGetZ(v2)
  55.             
  56.  
  57.     g = TCWDimensionHorizontal(TCWGetX(v1), TCWGetY(v1), TCWGetZ(v1), _ 
  58.                                  TCWGetX(v2), TCWGetY(v2), TCWGetZ(v2), _ 
  59.                                  TCWGetX(v3), TCWGetY(v3), TCWGetZ(v3))
  60.  
  61. ' the fourth vertex in a linear dimension is the one which 
  62.       ' defines the position of the dimension line
  63.     vd = TCWVertexAt(g, 3)
  64.  
  65.     res =TCWgetpoint(v3, "Dimension : Dimension Line Point", g, vd, &h00FC, 2)
  66.     if (res = 0) Then
  67.  
  68.        TCWGraphicDraw g, 0
  69.     Else
  70.  
  71.        TCWGraphicDispose g
  72.     End If
  73.    end if
  74.  
  75. 'Delete the vertices that didn't get added to any graphics or drawing
  76. TCWVertexDispose v1
  77. TCWVertexDispose v2
  78. TCWVertexDispose v3
  79. Stop
  80. end if
  81.   MsgBox "Script was cancelled."
  82.  
  83. end sub
  84.