
! script name: vpksolids.d/vpkcylindertube
! var_solids: construct a cylindrical tube solid

!A
!A NAME:
!A
!A 	Solid Cylindrical Tube VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This function constructs a cylindrical tube
!A
!B INSTRUCTIONS:
!B
!B 	OUTER RADIUS: Enter the outer radius of the tube to be constructed.
!B
!B 	THICHNESS: Enter the thickness of the tube to be constructed.
!B
!B	LENGTH: Enter the length of the tube. 
!B	
!B	LOCATION POINT: Input the location of the bottom of the tube.
!B
!B	AXIS DIRECTION POINT: Input a point specifing the direction of
!B				the tube axis.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: cylindrical tube  ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Radius_var$[256]
DIM Thickness_var$[256]
DIM Length_var$[256]

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
	Length= 125
ELSE
        R1= 1
	Length= 5
END IF

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

Stat= GLPlotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R1)
R1=InputRadius("OUTER 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(Thickness)
Thickness=GetValue("THICKNESS",Answer$)
IF ExitScript(Destination$) THEN Leave
No_thick_var= LastVariableInput(Thickness_var$)

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

Pick_point:Stat=SetInputFormat("n4=","")
Ps=XyzInput("CENTER POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Pick_point
E1= LastPickEnt
Para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Ps)
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created= WsFalse
END IF
Stat=SetLastPoint(Ps)
Stat= DeleteEntity(Ps)

Axis_point:Stat=SetInputFormat("n4=","")
Pe=XyzInput("AXIS DIRECTION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Axis_point
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
IF NOT ValidDependency(E2) THEN
        E2= CopyEntity(Pe)
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created= WsTrue
ELSE
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created= WsFalse
END IF
Stat= DeleteEntity(Pe)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("CYLINDER: Tube ")
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
IF No_thick_var THEN
        V3= FreeParameter("Thickness",Thickness)
ELSE
        V3= FreeParameter("Thickness",Thickness_var$)
END IF
IF No_length_var THEN
        V2= FreeParameter("Length",Length)
ELSE
        V2= FreeParameter("Length",Length_var$)
END IF
IF No_radius_var THEN
        V1= FreeParameter("Radius",R1)
	C1=WPKConicalTube(Ps,Pe,V1,V1,V2,V3)
ELSE
	C1=WPKConicalTube(Ps,Pe,Radius_var$,Radius_var$,V2,V3)
END IF
Stat= WPKNameBody(C1,Name$)
Stat= WPKSetBodyParent(C1)
Stat= DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("cylindrical tube")
IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_point

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