
! script name: vrotate.d/2drotateent
! var_topic: 2D rotate single entity

!A
!A NAME:
!A
!A 	Single Element: 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 ELEMENT TO BE ROTATED: Pick the element to be rotated.
!B
!B 	REFERENCE POINT : Pick the point to be used as the reference for
!B 		the rotate.
!B
!B 	ROTATION ANGLE: Enter the angular amount the entities should be
!B 		rotated.
!B
!B 	NUMBER OF TIMES: Enter the number of times the rotation process
!B 		should be repeated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: 2d rotate entity ")

DIM Answer$[256]
DIM Destination$[256]
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

Start: !
ActivateUndo

Stat= SetInputFormat("n4","")

E1= PickEntity("PICK ELEMENT TO BE ROTATED",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Start
Stat= EntityNameCheck(E1,Element$)

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
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$)

Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: 2d rotate ent")
Stat= SetRecDelLastExec
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)
		E2= PlaneRotateEntity(Element$,Pc,V1,V2)
	ELSE
		E2= PlaneRotateEntity(Element$,Pc,V1,Ntimes_var$)
	END IF
    ELSE
	IF No_times_var THEN
		V2= FreeParameter("Number",Number)
		E2= PlaneRotateEntity(Element$,Pc,Angle_var$,V2)
	ELSE
		E2= PlaneRotateEntity(Element$,Pc,Angle_var$,Ntimes_var$)
	END IF
    END IF
    Stat= AutoNameGroup(E2,Name$)
    ActivateUndo
    Stat= AdvanceUndoNumber("rotate entity")
    Stat= AddGroupToUndo(WsUBCreateMode,E2,0,WsFalse)
    Stat= DeleteEntity(E2)
ELSE
    IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
		E2= PlaneRotateEntity(Element$,Pc,V1)
    ELSE
		E2= PlaneRotateEntity(Element$,Pc,Angle_var$)
    END IF
    Stat= NameEntity(E2,Name$)
    ActivateUndo
    Stat= AdvanceUndoNumber("rotate entity")
    Stat= AddItemToUndo(WsUBCreateMode,E2)
END IF
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pt)

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

