
! script name: vrotate.d/axisrotateent
! var_topic: axis rotate single entity

!A
!A NAME:
!A
!A 	Single Element: Axis Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows an entity to be rotated about an axis in 3d space.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT TO BE ROTATED: Pick the element to be rotated.
!B
!B 	ROTATION ANGLE: Enter the angular amount the entities should be
!B 		rotated.
!B
!B 	PICK AXIS LINE: Pick the axis line for the entities to be rotated
!B 		around.
!B
!B 	NUMBER OF TIMES: Enter the number of times the rotation process
!B 		should be repeated.
!B

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

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","")

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

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


Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: axis rotate ent")
Stat= SetRecDelLastExec
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)
		E2= RotEntAboutAxis(Element$,Axis_line$,V1,V2,V3)
	   ELSE
		E2= RotEntAboutAxis(Element$,Axis_line$,Angle_var$,V2,V3)
	   END IF
	ELSE
	   IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
		E2= RotEntAboutAxis(Element$,Axis_line$,V1,Ntimes_var$,V3)
	   ELSE
		E2= RotEntAboutAxis(Element$,Axis_line$,Angle_var$,Ntimes_var$,V3)
	   END IF
	END IF
	Stat= AutoNameGroup(E2,Name$)

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

        Stat= DeleteEntity(E2)
ELSE
	V2= FreeParameter("Number",1)
	IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
		E2= RotEntAboutAxis(Element$,Axis_line$,V1,V2,V3)
	ELSE
		E2= RotEntAboutAxis(Element$,Axis_line$,Angle_var$,V2,V3)
	END IF
	Stat= NameEntity(E2,Name$)

	ActivateUndo
	Stat= AdvanceUndoNumber("rotate entity")
	Stat= AddItemToUndo(WsUBCreateMode,E2)

END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

Leave: !
stat= SetInputFormat("n4","")

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

