
! script name: move.d/dyncopydetail
! topic: dynamic copy in box for detailing

!A
!A NAME:
!A
!A 	Dynamic Copy In Box for detailing.
!A
!A DESCRIPTION:
!A
!A 	This script allows copys entities in a box graphically.
!A
!B INSTRUCTIONS:
!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
!B 		Hitting the Select Button on the mouse will select the location.
!B 		The numeric keypad controls the orientation.
!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 		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
!C NOTES:
!C
!C 	The geometry created for the detail is completely devoid of any of the
!C 	property associations that may be present in the original entities.
!C 	Likewise any groups or other geometry which may be present are unlinked
!C 	in the detail.
!C
!C 	For this script to function correctly the current view must be the same
!C 	as the workplane. That is, the operator must be looking at the
!C 	workplane as if it were a top view.
!C
!C 	The Pick box can be rectangular or circular. It uses the first argument
!C 	to determine rectangle or circle.
!C
!C 	The second argument determines the detail type.
!C
!C		0: Default Pick boundary on, Detail Boundary Off
!C		1: Pick boundary On, Detail Boundary On
!C		2: Pick boundary On, Detail Boundary Off
!C		3: Pick boundary Off, Detail Boundary On
!C		4: Pick boundary Off, Detail Boundary Off
!C
!# see also - points.d/xyzinput.hlp

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

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


Scale_factor= 1.0
Ask_scale= 1
IF ARGC>1 THEN
        A$= ARGV(1)
        Answer$= UPC$(A$)
        IF POS(Answer$,"CIRCLE") THEN Pick_box_type= 2
        IF ARGC>2 THEN
                A$= ARGV(2)
                Scale_factor= VAL(A$)
                Ask_scale= 0
                IF Scale_factor<= 0.0 THEN Ask_scale=1
        END IF
END IF

Cutout_ltype= 7
Detail_ltype= 7
Detail_type= GetDefault(WsDetailCopyType)
SELECT Detail_type
CASE 0
	Pick_rectangle= WsTrue
	Bdy_rectangle= WsFalse
CASE 1
	Pick_rectangle= WsTrue
	Bdy_rectangle= WsTrue
CASE 2
	Pick_rectangle= WsTrue
	Bdy_rectangle= WsFalse
CASE 3
	Pick_rectangle= WsFalse
	Bdy_rectangle= WsTrue
CASE 4
	Pick_rectangle= WsFalse
	Bdy_rectangle= WsFalse
END SELECT

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

Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

Start: !
ActivateUndo

IF Ask_scale THEN
	Stat= SetInputFormat("n4=","")
	Stat= SetEqualsValue(Scale_factor)
	Scale_factor= GetValue("SCALE FACTOR",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
END IF


Stat=SetPickMask(WsPickAll)
stat= SetInputFormat("n4","")
Pick_group=CreateGroup("TEMP")
PlotOff
P1= PointXYZ(0,0,0)
P2= PointXYZ(0,0,0)
Stat= MakeInvisible(P1)
Stat= MakeInvisible(P2)
PlotOn
Vnum= LastPickView
Stat=PickBox(Pick_group,Vnum,WsPickPen,Pick_box_type,P1,P2)
IF ExitScript(Destination$) THEN Leave

IF NOT ValidGeometry(Pick_group) THEN Start
IF GroupCount(Pick_group)=0 THEN
	Stat= DeleteEntity(Pick_group)
	GOTO Start
END IF
Stat= PlotEntity(Pick_group)
Stat= RemoveDimsFromGrp(Pick_group)
IF NOT ValidGeometry(Pick_group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Pick_group) THEN 
		Stat= DeleteEntity(Pick_group)
		GOTO Start
	END IF
END IF

PlotOff
Islands=CreateGroup("ISLANDS")
Group2= CopyGroup(Pick_group)
Stat= UnLink(Group2)
IF Pick_box_type=2 THEN
	Radius= DistTwoPts(P1,P2)
	C1= RadiusCenter(Radius,P1)
	Contour=CreateGroup("CONTOUR")
	Stat= AddToGroup(Contour,C1)
ELSE
	Contour= RectangleTwoPts(P1,P2,0.0,WsCornerFillet)
END IF
Trim_group=BoundaryTrim(Contour,Islands,Group2,WsInside)
Stat= DeleteEntity(Islands)
Stat= DeleteGroup(Group2,WsTrue)
Stat= DeleteEntity(Pick_group)
IF (ValidGeometry(Trim_group)) THEN
        Stat= PlotEntity(Trim_group)
	Pref= CopyEntity(P2)
	Group1= Trim_group
	Stat= DeleteEntity(P1)
	Stat= DeleteEntity(P2)
ELSE
	Stat= DeleteEntity(P1)
	Stat= DeleteEntity(P2)
	GOTO Start
END IF
Stat= LTypeContour(Contour,Cutout_ltype)
PlotOn
Stat= PlotEntity(Contour)



Angle= 0
P1= PointXYZ(0,0,1)
Paxis= AddVectors(Pref,P1)
Stat= DeleteEntity(P1)
Axis_line= LineTwoPoints(Pref,Paxis)

Place_group:!
PlotOff
Pdest= CopyEntity(Pref)
Group2= ScaleGroup(Group1,Pref,Scale_factor)
Contour2= ScaleGroup(Contour,Pref,Scale_factor)
Stat= LTypeContour(Contour2,Detail_ltype)

Stat=DynLabel("Rotate Angle:"&VAL$(Angle))
Group= CreateGroup("TEMP")
Stat= AddToGroup(Group,Contour2)
Stat= AddToGroup(Group,Group2)
Stat= UnAssocAllEntProps(Group)

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

Stat=DynLabel("")
IF NOT Bdy_rectangle THEN
	Stat= RemoveFromGrp(Group,1)
	Stat= DeleteGroup(Contour2)
END IF

StdWorkplane
Pm= SubtractVectors(Pdest,Pref)
Shift_trans=AngleTransform(Pm,0,0,0,WsWorkplaneVals)
Axis_trans= RotAboutAxisTrans(Axis_line,Rotate_angle)
Trans1=MultTransforms(Shift_trans,Axis_trans)
Stat=TransGroupTrans(Group,Trans1,WsTrue)
Stat= MakeVisible(Group2)
Stat= PlotEntity(Group2)

ActivateUndo
Stat= AdvanceUndoNumber("copy")
Stat= AddGroupToUndo(WsUBCreateMode,Group2,2,WsTrue)
IF Bdy_rectangle THEN
	Stat= AddGroupToUndo(WsUBCreateMode,Contour2,2,WsTrue)
END IF
IF Pick_rectangle THEN
	Stat= AddGroupToUndo(WsUBCreateMode,Contour,2,WsTrue)
END IF

Stat=Unlink(Group2)
Stat= DeleteEntity(Group2)
Stat=Unlink(Contour2)
Stat= DeleteEntity(Contour2)
Stat= DeleteEntity(Group)

Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pdest)

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

Stat=SetPickMask(WsPickAll)
Stat= PlotEntity(Group1)
Stat= DeleteGroup(Group1,WsTrue,WsTrue)
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
Stat= DeleteEntity(Paxis)
Stat= DeleteEntity(Axis_line)
IF NOT Pick_rectangle THEN
        Stat= DeleteGroup(Contour,WsTrue)
ELSE
	Stat= PlotEntity(Contour)
	Stat=Unlink(Contour)
	Stat= DeleteEntity(Contour)
END IF
Stat=SetPickMask(WsPickAll)
GOTO Start

Leave: !
Stat=DynLabel("")
ActivateUndo
IF NOT Pick_rectangle THEN
        Stat= DeleteGroup(Contour,WsTrue)
END IF
Stat=SetPickMask(WsPickAll)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pick_group)
Stat= DeleteEntity(Group1)
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
