
! script name: vsolids.d/cylinderrev
! var_topic: construct revolution for cylinder

!A
!A NAME:
!A
!A 	Revolution: cylinder with corner radii along Axis	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder using the line that is graphically
!A 	picked as the axis of the cylinder.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder.
!B
!B 	STARTING ANGLE: Enter the starting angle of the cylinder.
!B
!B 	ANGULAR EXTENT: Enter the number of degrees and the direction
!B 		( + CCW, - CW ) from the starting angle to the ending angle.
!B 		The angular extent determines the ending angle.
!B
!B 	CORNER RADIUS: Enter the corner radius of the cylinder.
!B
!B
!B 	PICK AXIS LINE: Pick the line to be used as the axis of the cylinder.
!B
!C NOTES:
!C
!C 	The U contours of a cylinder are the circles and the V contours
!C 	are the lines.
!C
!D
!D 		ClosedEnds            0
!D 		OpenFrontEnd          1
!D 		OpenBackEnd           2
!D

Stat=ChangeLabelStr("ScriptNameStatus","Function: revolution cylinder ")

DIM Destination$[256]
DIM Answer$[256]
DIM Type$[256]
DIM Sradius_var$[256]
DIM Eradius_var$[256]
DIM Crad_var$[256]
DIM Length_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Name$[256]
DIM Axis_line$[256]

C_type=0
IF ARGC>1 THEN
	Type$= ARGV(1)
	C_type= VAL(Type$)
END IF

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave


ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
        R3= 3
ELSE
        R1= 1
        R3= 0.125
END IF
Astart= 0
Angle= 180

Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R1)
R1=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave
No_sradius_var= LastVariableInput(Sradius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Cloop
        No_sradius_var=0
        Stat= EntityNameCheck(C1,Sradius_var$)
END IF

Stat=SetRadiusEquals(R3)
R3=InputRadius("CORNER RADIUS")
IF ExitScript(Destination$) THEN Leave
No_crad_var= LastVariableInput(Crad_var$)


Stat=SetAngleEquals(Astart)
Astart=InputAngle("STARTING ANGLE ( 0 90 180 270) ")
IF ExitScript(Destination$) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Angle)
Angle=GetValue("ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)


Pick_axis:!
Stat=SetInputFormat("n4","")
Axis_line=PickSpecificEnt("PICK AXIS LINE",WsPickLines)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Axis_line) THEN Pick_axis
Stat= EntityNameCheck(Axis_line,Axis_line$)

T=LastPickPara
IF T<=0.5 THEN
        Direction= WsForward
ELSE
        Direction= WsReverse
END IF


Stat= GenerateVarName(WsCylSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CYLINDER: Closed cylinder")
Stat= SetRecDelLastExec
IF No_crad_var THEN
        V3= FreeParameter("Corner Radius",R3)
ELSE
        V3= FreeParameter("Corner Radius",Crad_var$)
END IF
IF No_astart_var THEN
        V4= FreeParameter("Astart",Astart)
ELSE
        V4= FreeParameter("Astart",Astart_var$)
END IF
IF No_angle_var THEN
        V5= FreeParameter("Angle",Angle)
ELSE
        V5= FreeParameter("Angle",Angle_var$)
END IF
IF No_sradius_var THEN
        V1= FreeParameter("Radius",R1)
	C1=RevolutionCone(Axis_line$,C_type,V1,V1,V4,V5,V3,Direction)
ELSE
	C1=RevolutionCone(Axis_line$,C_type,Sradius_var$,Sradius_var$,V4,V5,V3,Direction)
END IF
Stat= NameEntity(C1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("closed cylinder")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Cloop

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
