home *** CD-ROM | disk | FTP | other *** search
- 'Sample that shows how to do a linear copy of selected graphics
- '
- ' Author : Tamara Cartwright
- ' Date : 01/26/97
-
-
- ' Misc
- Global Const NULL = 0
-
- dim v1 as long
- dim v2 as long
- dim copies as long
- dim hActive as long
-
- sub Main
-
- 'Get drawing handle
- hActive = TCWDrawingActive()
-
- if (hActive = NULL) then
- MsgBox "Need active drawing."
- 'Terminate Program
- Stop
- end if
-
- 'Get number of copies from the user
- copies = Val(InputBox$("Input number of copies to make"))
-
- 'create a vertex
- v1 = TCWVertexCreate(0.0, 0.0, 0.0)
-
- if (v1 = NULL) then
- MsgBox "Cannot create vertex"
- Stop
- end if
-
- v2 = TCWVertexCreate(0.0, 0.0, 0.0)
- if (V2 = NULL) then
- MsgBox "Cannot create vertex"
- Stop
- end if
-
- 'click on screen to get points
- result = TCWGetPoint(v1,"Get first point", NULL, NULL, 0, 1)
- result = TCWGetPoint(v2,"Get second point", NULL, NULL, 0, 1)
-
- If copies = 0 Then
- MsgBox "No copies desired, finished!"
- Stop
- end if
-
- 'Go and copy away
- DoCopy
-
- 'Need to delete the two vertex objects that we created above
- TCWVertexDispose v1
- TCWVertexDispose v2
-
- End Sub
-
- Sub DoCopy ()
- Dim gCount As Long
- Dim sCount As Long
- Dim ga As Long
- dim g as Long
-
- dim i as integer
- dim j as integer
- dim result as long
-
- dim dx as double
- dim dy as double
- dim dz as double
-
-
- 'Get selection count to see that we have something selected
- sCount = TCWSelectionCount
-
- if (sCount = NULL) then
- MsgBox "Program requires at least one graphic to be selected."
- 'Terminate the program
- Stop
- end if
-
- 'Calculate the delta between the points for the copy
- dx = (TCWGetX(v2) - TCWGetX(v1))
- dy = (TCWGetY(v2) - TCWGetY(v1))
- dz = (TCWGetZ(v2) - TCWGetZ(v1))
-
- for i = 1 to copies
- 'Get total graphics in drawing
- gCount = TCWGraphicCount(hActive)
-
- 'loop through selected graphics making copies
- for j = 0 to sCount-1
- ga = TCWSelectionAt(j)
- if (ga = NULL) then
- MsgBox "Lost Selection?"
- Stop
- end if
-
- 'make copy of selected graphic
- g = TCWGraphicCopy(ga)
-
- 'add copy to the drawing
- result = TCWGraphicAppend(NULL, g)
- next j
-
- 'Deselect the original graphics
- TCWDeSelectAll
-
- 'Select the newly added graphics that we just copied
- 'they will be at gCount+1...
- for j = 0 to sCount-1
- ga = TCWGraphicAt(hActive, gCount+j)
-
- if (ga = NULL) then
- MsgBox "Cannot find new copied graphic"
- stop
- end if
-
- 'select the graphic
- result = TCWGraphicPropertySet(ga, "Selected", 1)
- next j
-
- 'move the selection on the vector
- TCWSelectionMove dx, dy, dz
-
- 'Select the newly added graphics that we just copied again,
- 'TCWSelectionMove loses the selection state
- for j = 0 to sCount-1
- ga = TCWGraphicAt(hActive, gCount+j)
- if (ga = NULL) then
- MsgBox "Lost selection"
- stop
- end if
-
- 'set selected
- result = TCWGraphicPropertySet(ga, "Selected", 1)
- next j
-
- next i
-
- End Sub
-
-