
! script name: vsolids.d/cylinder
! var_topic: construct cylinder of specified length, radius, and orientation

!A
!A NAME:
!A
!A 	Cylinder: Define	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder of specified length, radius,
!A 	and orientation at the specified center point.
!A
!A~ image location - images/cylinder.gif
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder to be constructed.
!B
!B 	LENGTH: Enter the length of the cylinder to be constructed.
!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~ image location - images/AngExtent.gif
!B
!B 	CENTER POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the center
!B 		point of the cylinder.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	AXIS ROTATION ANGLE: Enter the orientation angle of the axis line of
!B 		the cylinder in the XY plane.
!B
!B 	AXIS TILT ANGLE: This represents the angle of tilt of the axis line
!B 		of the cylinder with respect to the XY plane.
!B
!B 	AXIS ROLL ANGLE: This represents the roll angle around the axis line
!B 		of the cylinder.
!B
!C NOTES:
!C
!C 	The U contours of a cylinder are the circles and the V
!C 	contours are the lines.
!C
!# see also - points.d/xyzinput.hlp


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

DIM Destination$[256]
DIM Answer$[256]
DIM Radius_var$[256]
DIM Length_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Name$[256]
DIM Center$[256]
DIM Xangle_var$[256]
DIM Yangle_var$[256]
DIM Zangle_var$[256]
DEG

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
        Length= 100
ELSE
        R1= 1
        Length=5
END IF
Astart= 0
Angle= 180

Cloop:!

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


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Length)
Length=GetValue("LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_length_var= LastVariableInput(Length_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_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("CENTER POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Stat=SetAngleEquals(0)
Zangle=InputAngle("AXIS ROTATION ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)

Zangle=Zangle-90

Stat=SetAngleEquals(0)
Xangle=InputAngle("AXIS TILT ANGLE ",WsSigned)
IF (ExitScript(Destination$)) THEN Leave
No_xangle_var= LastVariableInput(Xangle_var$)

Stat=SetAngleEquals(0)
Yangle=InputAngle("AXIS ROLL ANGLE ",WsSigned)
IF (ExitScript(Destination$)) THEN Leave
No_yangle_var= LastVariableInput(Yangle_var$)


Stat= GenerateVarName(WsCylSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CYLINDER: Define")
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 No_length_var THEN
        V2= FreeParameter("Length",Length)
ELSE
        V2= FreeParameter("Length",Length_var$)
END IF
IF No_astart_var THEN
        V3= FreeParameter("Astart",Astart)
ELSE
        V3= FreeParameter("Astart",Astart_var$)
END IF
IF No_angle_var THEN
        V4= FreeParameter("Angle",Angle)
ELSE
        V4= FreeParameter("Angle",Angle_var$)
END IF
IF No_xangle_var THEN
        V5= FreeParameter("X Angle",Xangle)
ELSE
        V5= FreeParameter("X Angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V6= FreeParameter("Y Angle",Yangle)
ELSE
        V6= FreeParameter("Y Angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V7= FreeParameter("Z Angle",Zangle)
ELSE
        V7= FreeParameter("Z Angle",Zangle_var$)
END IF
Trans1=AngleTransform(Pc,V5,V6,V7,WsWorkplaneVals)
IF No_radius_var THEN
        V1= FreeParameter("Radius",R1)
	C1=Cylinder(Trans1,V1,V2,V3,V4)
ELSE
	C1=Cylinder(Trans1,Radius_var$,V2,V3,V4)
END IF
Stat= NameEntity(C1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cylinder")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Cloop

Leave:!
Stat=DeleteEntity(Pc)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
