
! script name: vpksheets.d/vpkcircylinder
! var_solids: construct cylinder defined by a circle and length

!A
!A NAME:
!A
!A 	Cylinder: Circle	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a cylinder of specified length and the circle
!A 	picked will be used as one end of the cylinder and will determine the
!A 	radius and orientation of the cylinder.
!A
!A~ image location - images/circylinder.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK CIRCLE: Pick the circle to be used as one end of the cylinder
!B 		to be constructed.
!B
!B 	LENGTH: Enter the length of the cylinder to be constructed.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: cylinder defined by a circle ")

DIM Destination$[256]
DIM Answer$[256]
DIM Length_var$[256]
DIM Circle$[256]
DIM Name$[256]

Units= CurrentUnits
IF Units= WsMetric THEN
        Length= 100
ELSE
        Length= 5
END IF

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

Stat= GLPlotOn
ActivateUndo
Cloop:!
Stat=SetInputFormat("n4","")
pcircle=PickSpecificEnt("PICK CIRCLE",WsPickCircles)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(pcircle) THEN Cloop
Stat= EntityNameCheck(pcircle,Circle$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Length)
Length=GetValue("LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_length_var= LastVariableInput(Length_var$)

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: cylinder from circle")
IF No_length_var THEN
        V1= FreeParameter("Length",Length)
ELSE
        V1= FreeParameter("Length",Length_var$)
END IF
C1=CircleCylinder(Circle$,V1)
RecordFunctionOff
IF ValidGeometry(C1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        G1=WPKMakeBsurf(C1)
        Stat= WPKNameBodyGroup(G1,Name$)
        Stat= WPKSetBodyParent(G1,1)
        Stat= DeleteEntityList(G1,C1)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
        DelLastVarRecord
ELSE
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("cylinder sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

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