
! script name: vrotate.d/2drotposent
! var_topic: 2D rotate and position single entity

!A
!A NAME:
!A
!A 	Single Element: 2D Rotate and Position VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script rotates and positions and entity.
!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 	DESTINATION POINT : Pick the destination point.
!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 and position entity ")

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Name$[256]
DIM Center$[256]
DIM Point$[256]
DIM Angle_var$[256]
DEG
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

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$)
Stat= SetSelectedFlag(E1,WsTrue)
Stat= PlotEntity(E1)

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Ref_point
Para1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)

Dest_point:E2=PickEntity("DESTINATION POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Dest_point
Para2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point$)

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


Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: 2d rotate and position ent")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pt= ParameterReturnPt(Point$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pt= ParameterReturnPt(Point$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pt= ParameterReturnPt(Point$,Para2,WsGeomCenter)
END SELECT
IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
	E2= PlaneRotateEntity(Element$,Pc,V1)
ELSE
	E2= PlaneRotateEntity(Element$,Pc,Angle_var$)
END IF
Move_vector= VectorTwoPts(Pc,Pt)
E3= VectorCopyEntity(E2,Move_vector)
Stat= NameEntity(E3,Name$)
Stat= DeleteEntity(E2)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(Pt)
Stat= DeleteEntity(Move_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= SetSelectedFlag(E3,WsFalse)

ActivateUndo
Stat= AdvanceUndoNumber("rotate entity")
Stat= AddItemToUndo(WsUBCreateMode,E3)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Dest_point

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

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

