home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2002 March
/
PCWMAR02.iso
/
software
/
turbocad
/
V4
/
tcw.z
/
lincopy.bas
< prev
next >
Wrap
BASIC Source File
|
1997-10-28
|
4KB
|
160 lines
'Sample that shows how to do a linear copy of selected graphics.
' Author : Tamara Cartwright, Natalia Karaseva (updated to version 4.0 interface)
' Date : 01/26/97, 09/30/97
dim v1 as long
dim v2 as long
dim copies as long
dim hActive as long
dim sCount As Long
dim Ls As Long
sub Main
'Get drawing handle
hActive = TCWDrawingActive()
if (hActive = 0) then
MsgBox "Need active drawing."
'Terminate Program
Stop
end if
'Get selection count to see that we have something selected
sCount = TCWSelectionCount
if (sCount = 0) then
MsgBox "Program requires at least one graphic to be selected."
'Terminate the program
Stop
end if
'Get number of copies from the user
copies = Val(InputBox$("Input number of copies to make","TurboCAD"))
If copies = 0 Then
MsgBox "No copies desired, finished!"
Stop
end if
'create a vertex
v1 = TCWVertexCreate(0.0, 0.0, 0.0)
if (v1 = 0) then
MsgBox "Cannot create vertex"
Stop
end if
v2 = TCWVertexCreate(0.0, 0.0, 0.0)
if (V2 = 0) then
MsgBox "Cannot create vertex"
Stop
end if
'click on screen to get points
result = TCWGetPoint(v1,"Get first point", 0, 0, 0, 1)
if result<0 then
Msgbox "Script was cancelled."
Stop
End If
Ls= TCWSelectByQuery("")
result = TCWGetPoint(v2,"Get second point", 0, 0, 0, 1)
if result<0 then
Msgbox "Script was cancelled."
Stop
End If
Ls= TCWSelectByQuery("")
'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 ga As Long
dim g as Long
dim i as integer
dim k as integer
dim m as integer
dim n as integer
dim result as long
dim NUL as Long
dim dx as double
dim dy as double
dim dz as double
'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 k = 0 to sCount-1
ga = TCWSelectionAt(k)
if (ga = 0) then
MsgBox "Lost Selection?"
Stop
end if
'make copy of selected graphic
g = TCWGraphicCopy(ga)
'add copy to the drawing
result = TCWGraphicAppend(NUL, g)
next k
'Deselect the original graphics
TCWDeSelectAll
'Select the newly added graphics that we just copied
'they will be at gCount+1...
n=0
for n = 0 to sCount-1
ga = TCWGraphicAt(hActive, gCount+n)
if (ga = 0) then
MsgBox "Cannot find new copied graphic"
stop
end if
'select the graphic
result = TCWGraphicPropertySet(ga, "Selected", 1)
next n
'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
m=0
for m = 0 to sCount-1
ga = TCWGraphicAt(hActive, gCount+m)
if (ga = 0) then
MsgBox "Lost selection"
stop
end if
'set selected
result = TCWGraphicPropertySet(ga, "Selected", 1)
next m
next i
TCWDeSelectAll
End Sub