
! script name: vrotate.d/axisrotatebox
! var_topic: axis rotate boxed group of entities

!A
!A NAME:
!A
!A 	Box: Axis Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities to be rotated
!A      about an axis line.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Select
!B 		the view for the rotation.
!B
!B 	PICK AXIS LINE: Pick the axis line
!B 		for the entities to be rotated around.
!B
!B 	ROTATION ANGLE: Enter the angular
!B 		amount the entities should be rotated.
!B
!B 	NUMBER OF TIMES: Enter the number of
!B 		times the rotation process should be repeated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: axis rotate boxed group ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Axis_line$[256]
DIM Angle_var$[256]
DIM Ntimes_var$[256]
DIM Element$[256]
DEG

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

Start: !
ActivateUndo

Stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")


Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF ExitScript(Destination$) THEN Leave

IF NOT ValidGeometry(Group) THEN 
	GOTO Start
ELSE
	IF NOT GroupCount(Group) THEN Start
END IF

Angle_ques:Angle=InputAngle("ROTATION ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
	IF NOT ValidDependency(L1) THEN Angle_ques
        No_angle_var=0
        Stat= EntityNameCheck(L1,Angle_var$)
END IF

Axis_line:Axis_line=PickSpecificEnt("PICK AXIS LINE ",WsPickLines)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Axis_line) THEN Axis_line
Stat= EntityNameCheck(Axis_line,Axis_line$)

Stat=SetEqualsValue(1)
Stat=SetInputFormat("n0=","")
Number=GetValue("NUMBER OF TIMES",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Number=0 THEN Start
No_times_var= LastVariableInput(Ntimes_var$)

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: axis rotate multi ent")
Stat= SetRecDelLastExec
Egroup= CreateGroup("Picked Entities")

FOR I=1 TO Num_elements
	RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Element$)
	IF ValidDependency(E1,WsFalse) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(Egroup,Element$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
V3= FreeParameter("Total shift along axis",0.0)
IF Number>1 THEN
        IF no_times_var THEN
	   V2= FreeParameter("Number",Number)
           IF No_angle_var THEN
	   	V1= FreeParameter("Angle",Angle)
                G1= RotGrpAboutAxis(Egroup,Axis_line$,V1,V2,WsFalse,V3)
           ELSE
                G1= RotGrpAboutAxis(Egroup,Axis_line$,Angle_var$,V2,WsFalse,V3)
           END IF
        ELSE
           IF No_angle_var THEN
	   	V1= FreeParameter("Angle",Angle)
                G1= RotGrpAboutAxis(Egroup,Axis_line$,V1,Ntimes_var$,WsFalse,V3)
           ELSE
                G1= RotGrpAboutAxis(Egroup,Axis_line$,Angle_var$,Ntimes_var$,WsFalse,V3)
           END IF
        END IF
ELSE
	V2= FreeParameter("Number",Number)
        IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
                G1= RotGrpAboutAxis(Egroup,Axis_line$,V1,V2,WsFalse,V3)
        ELSE
                G1= RotGrpAboutAxis(Egroup,Axis_line$,Angle_var$,V2,WsFalse,V3)
        END IF
END IF
Stat= AutoNameGroup(G1,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("axis rotate")
Stat= AddGroupToUndo(WsUBCreateMode,G1,2,WsTrue)
Stat= DeleteSubGroups(G1)
Stat= DeleteEntity(Egroup)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(G1)

GOTO Start

Leave: !
Stat= SetInputFormat("n4","")
Stat= DeleteEntity(Group)
Stat= DeleteEntity(G1)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

