
! script name: vrotate.d/2drotatemulti
! var_topic: 2D rotate picked group of entities

!A
!A NAME:
!A
!A 	Multiple Elements: 2D Duplicate		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A      rotated and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENTS TO BE ROTATED, Backup, Proceed: Pick
!B 		one of the elements to be rotated.  The question
!B 		will repeat until "PROCEED" is answered.
!B 		All elements picked will then be rotated.
!B
!B 		B - The backup option allows the last element picked to
!B 		    be removed from the group of elements to be rotated.
!B
!B 	REFERENCE POINT: Pick the point to
!B 		be used as the reference for the rotate.
!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: 2d rotate picked group ")

DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DIM Element$[256]
DIM Name$[256]
DIM Center$[256]
DIM Angle_var$[256]
DIM Ntimes_var$[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: E1= PickEntity("PICK ELEMENTS TO BE ROTATED"&Extras$,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                E1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
		Stat= SetSelectedFlag(E1,WsFalse)
                Stat= PlotEntity(E1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(E1) THEN
			IF NOT ValidDependency(E1) THEN Pick_ent
                        N1= ElementGrpNum(Group,E1)
                        IF NOT N1 THEN Stat=AddToGroup(Group,E1)
                        Extras$=", Backup , Proceed "
			Stat= SetSelectedFlag(E1,WsTrue)
                	Stat= PlotEntity(E1)
                END IF
        END IF

END LOOP


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

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E2) THEN Line_loop
IF NOT ValidDependency(E2) THEN Ref_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)
Pc= ParameterReturnPt(E2,T,Pick_return)

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
Stat= DeleteEntity(Pc)

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: 2d rotate mult 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) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(Egroup,Element$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF Number>1 THEN
    IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
        IF No_times_var THEN
		V2= FreeParameter("Number",Number)
                G1= PlaneRotateGroup(Egroup,Pc,V1,V2)
        ELSE
                G1= PlaneRotateGroup(Egroup,Pc,V1,Ntimes_var$)
        END IF
    ELSE
        IF No_times_var THEN
		V2= FreeParameter("Number",Number)
                G1= PlaneRotateGroup(Egroup,Pc,Angle_var$,V2)
        ELSE
                G1= PlaneRotateGroup(Egroup,Pc,Angle_var$,Ntimes_var$)
        END IF
    END IF
ELSE
    IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
		G1= PlaneRotateGroup(Egroup,Pc,V1)
    ELSE
		G1= PlaneRotateGroup(Egroup,Pc,Angle_var$)
    END IF
END IF
Stat= AutoNameGroup(G1,Name$)

ActivateUndo
Stat= AdvanceUndoNumber("rotate entities")
Stat= AddGroupToUndo(WsUBCreateMode,G1,2,WsTrue)

Stat= DeleteSubGroups(G1)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(Egroup)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
GOTO Start

Leave:!
Stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pt)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(G1)

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

