
! script name: pktransform.d/pkdyn3dcopy
! solids: dynamic 3d copy a body

!A
!A NAME:
!A
!A 	Graphical 3D Copy
!A
!A DESCRIPTION:
!A
!A 	This script graphically copies a body.
!A
!B INSTRUCTIONS:
!B
!B
!B 	REFERENCE POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point
!B 		to be used as the reference for the copy.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PICK DESTINATION POINT : The elements to be copied are displayed
!B		graphically with the cursor. 
!B		Hitting the Select Buttonon the mouse will select the location.
!B		The numeric keypad controls the orientation.
!B
!B			(6) 0   degree orientation.
!B			(9) 45  degree orientation.
!B			(8) 90  degree orientation.
!B			(7) 135 degree orientation.
!B			(4) 180 degree orientation.
!B			(1) 225 degree orientation.
!B			(2) 270 degree orientation.
!B			(3) 305 degree orientation.
!B
!B 		Plus (+) and (-) turn the entities +/- the angular increment.
!B		The Default angular increment is 5 degrees. 
!B		Hitting ( A ) will change the increment to 10 degrees.		
!B		Hitting ( a ) will change the increment to 1 degrees.		
!B		Hitting ( F ) or ( f ) will change the increment to 0.1 degrees.
!B		Hitting ( D ) or ( d ) will return the increment to 5 degrees.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic 3d copy ")

DIM Answer$[256]
DIM Destination$[256]
DEG

Place_min= NamedVarVal("Graph place min",WsSystemVars,50)
Place_max= NamedVarVal("Graph place max",WsSystemVars,500)
Place_density= NamedVarVal("Graph place density",WsSystemVars,3)

Start: !
ActivateUndo
Stat=SetPickMask(WsPickAll)
Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

stat= SetInputFormat("n4","")
Stat= GLPlotOn
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY TO BE COPIED")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Start
        Pkbody= WPKParentBody(E1)
END IF

Stat=SetPickMask(WsPickNoSurf)
Pref=XyzInput("REFERENCE POINT ",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
Stat= SetLastPoint(Pref)

Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Xangle)
Xangle=GetValue("X AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetEqualsValue(Yangle)
Yangle=GetValue("Y AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetEqualsValue(Zangle)
Zangle=GetValue("Z AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Place_group:!
Angle= 0
PlotOff
Pdest= CopyEntity(Pref)
P1= PointXYZ(0,0,1)
Paxis= AddVectors(Pref,P1)
Stat= DeleteEntity(P1)
Axis_line= LineTwoPoints(Pref,Paxis)
Stat= DeleteEntity(Paxis)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
Stat= MakeInvisible(Axis_line)
Orient= Rot3dAnglesTrans(Pref,Xangle,Yangle,Zangle)
Group1= WPKConvertBody(Pkbody,WsPKConvertEdges)
Stat=TransGroupTrans(Group1,Orient)
PlotOn

Stat=SetPickMask(WsPickNoSurf)
Vnum= LastPickView
stat= SetInputFormat("n4b","")
Group2= MakeSparseGroup(Group1,Place_min,Place_max,Place_density)
Stat= MakeInvisible(Group1)
Rotate_angle= DynamicMoveGroup(Vnum,Group2,Pref,Pdest,Angle,"PICK DESTINATION POINT")
Stat= DeleteEntity(Group2)
Stat= DeleteGroup(Group1,WsTrue)
IF ExitScript(Destination$) THEN 
	GOTO Leave
END IF


StdWorkplane
Trans1= Rot3DMoveAxisTrans(Pdest,Axis_line,Rotate_angle,Xangle,Yangle,Zangle)

PlotOn
WPKClearErrorFlag
E2=WPKTransCopyBody(Pkbody,Trans1)
ActivateUndo
Stat= AdvanceUndoNumber("3d copy body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

PlotOff
Stat= SetLastPoint(Pdest)
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pdest)
Stat= DeleteEntity(Paxis)
Stat= DeleteEntity(Axis_line)
PlotOn

IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

Stat=SetPickMask(WsPickAll)
GOTO Place_group

Leave: !
PlotOn
ActivateUndo
Stat=SetPickMask(WsPickAll)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

stat= SetInputFormat("n4","")
Stat= DeleteGroup(Group1,WsTrue)
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
Stat= DeleteEntity(Paxis)
Stat= DeleteEntity(Axis_line)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
