
! script name: pkdyn_solids.d/pkdynaxiscyl
! solids: construct cylinder along an axis line

!A
!A NAME:
!A
!A 	Dynamic Cylinder: Axis
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder using the line that would be
!A 	created between the two points that are picked, as the axis line of
!A 	the cylinder.  The length of the cylinder is determined by the distance
!A 	between the two points that are picked.
!A
!A~ image location - images/cylaxis.gif
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder to be constructed.
!B
!B
!B~ image location - images/AngExtent.gif
!B
!B 	AXIS START: Pick the axis start point of the cylinder.
!B
!B 	PICK AXIS ENDPOINT: Pick the axis endpoint for the cylinder.
!B
!# see also - points.d/dyninput.hlp
!# see also - htdocs/help.d/parasolids.htm


Stat=ChangeLabelStr("ScriptNameStatus","Function: cylinder along an axis line ")

DIM Destination$[256]
DIM Answer$[256]
REAL params(0:10)

Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF

Stat= GLPlotOn
Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo

Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

Dynamic_radius= GetDefault(WsDynRadiusDefault)
Dynamic_angle= GetDefault(WsDynAngleDefault)

Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng1Incr,0.0)
Stat= SetDefaults(WsDynamicAng2Incr,0.0)

Cloop:!
Stat=SetInputFormat("n4b=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave

Pick_axis:!
Stat=DynLabel("Radius:"&VAL$(Radius))
Stat=SetInputFormat("n4b","")
Ps=XyzInput("AXIS START",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Pick_axis

Stat=SetLastPoint(Ps)
PlotOff
length1= 2.0*Radius
Pe= PtIncrXyz(Ps,0.0,Length1,0.0)
Axis_line= LineTwoPoints(Ps,Pe)
C1=AxisLineCylinder(Axis_line,Radius,Astart,Angle,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= HideEntity(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= Length1
Params(2)= 0.0
Params(3)= 360
Num_params=4
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynAxisCylinder,"PICK AXIS ENDPOINT ",Params,Num_params,0,WsTrue,WsFalse)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(C1,WsTrue)
	Stat=DeleteEntity(Ps)
        Stat=DeleteEntity(Pe,WsTrue)
        Stat=DeleteEntity(Axis_line,WsTrue)
        IF Destination$= "BACKUP" THEN Pick_axis
        GOTO Leave
END IF
Radius= Params(0)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

WPKClearErrorFlag
C2=WPKBasicSolid(C1)
Stat=DeleteEntity(C1)

ActivateUndo
Stat= AdvanceUndoNumber("solid cylinder")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Pick_axis

Leave:!
Stat=DynLabel("")
Stat=SetPickMask(WsPickGeometry)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
	IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
