
! script name: vrotate.d/axisrotmcont
! var_topic: rotates multiple contours about an axis.

!A
!A NAME:
!A
!A 	Multiple Groups: Axis Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows multiple contours to be rotated about an axis.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOURS TO BE ROTATED, Backup, Proceed: Pick
!B 		one of the contours to be rotated.  The question
!B 		will repeat until "Proceed" is selected.  All
!B 		contours picked will then be rotated.
!B
!B 		B - The backup option allows the last element picked to
!B 		    be removed from the group of contours to be rotated.
!B
!B 	ROTATION ANGLE: Enter the angular amount
!B 		the contours should be rotated.
!B
!B 	PICK AXIS LINE: Pick the axis line for the
!B 		entities to be rotated around.
!B
!B 	NUMBER OF TIMES: Enter the number of times
!B 		the rotation process should be repeated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: axis rotate multiple contours ")

DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DIM Name$[256]
DIM Axis_line$[256]
DIM Angle_var$[256]
DIM Ntimes_var$[256]
DIM Contour$[256]
DEG

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")
Extras$= ""
LOOP
        stat= SetInputFormat("a1",",P,B,")
Pick_ent:Contour= PickGroupEnt("PICK CONTOURS TO BE ROTATED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                C1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
                Stat= SetSelectedFlag(C1,WsFalse)
                Stat= PlotEntity(C1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(Contour) THEN
                IF NOT ValidDependency(Contour) THEN Pick_ent
                IF IsEntityDependent(Contour)= WsFalse THEN
                   stat= SetInputFormat("a99","")
                   Stat= GetValue("NOT A VARIATIONAL CONTOUR, Proceed ",Answer$)
                   IF ExitScript(Destination$) THEN Leave
                   GOTO Pick_ent
                END IF
                        N1= ElementGrpNum(Group,Contour)
                        IF NOT N1 THEN Stat=AddToGroup(Group,Contour)
                        Extras$=", Backup , Proceed "
                        Stat= SetSelectedFlag(Contour,WsTrue)
                        Stat= PlotEntity(Contour)
                END IF
        END IF

END LOOP
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$)


Stat= SetSelectedFlag(Group,WsFalse)
Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: axis rotate multi contours")
Stat= SetRecDelLastExec
G1= CreateGroup("Picked Entities")
FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Contour$)
	IF ValidDependency(E1) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(G1,Contour$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
IF no_times_var THEN
    V2= FreeParameter("Number",Number)
    IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
        G2= AxisRotGrpOfGrps(G1,Axis_line$,V1,V2,WsTrue)
    ELSE
        G2= AxisRotGrpOfGrps(G1,Axis_line$,Angle_var$,V2,WsTrue)
    END IF
ELSE
    IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
        G2= AxisRotGrpOfGrps(G1,Axis_line$,V1,Ntimes_var$,WsTrue)
    ELSE
        G2= AxisRotGrpOfGrps(G1,Axis_line$,Angle_var$,Ntimes_var$,WsTrue)
    END IF
END IF
Stat= AutoNameGroup(G2,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("rotate contours")
Stat= AddGroupToUndo(WsUBCreateMode,G2,3,WsTrue)
Stat= DeleteSubGroups(G2)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Axis_line)
Stat= PlotEntity(Group)
Stat= DeleteEntityList(Group,G1)

GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Axis_line)
Stat= PlotEntity(Group)
Stat= DeleteEntityList(Group,G1)

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

