
! script name: vpksheets.d/vpksphereaxis
! var_solids: construct sphere along an axis line

!A
!A NAME:
!A
!A 	Sphere: Sphere along an axis line.	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a sphere along an axis line.  A sphere
!A 	is the set of all points in 3d space equidistant from a fixed point.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius, the measure of the constant distance from
!B 		the center of the sphere.
!B
!B 	STARTING LENGTH: Enter the controlling extent of the sphere along the
!B 		axis, negative measures backward from the starting point, zero
!B 		is the center or starting point.
!B
!B 	ENDING LENGTH: Enter the controlling extent of the sphere along the
!B 		axis, positive measures forward from the starting point, zero
!B 		is the center or starting point.
!B
!B 		NOTE: The starting length and ending length should not exceed
!B 		the radius of the sphere.  The default value indicates the
!B 		limits.
!B
!B 	STARTING ANGLE: Enter the starting angle of the sphere.  The starting
!B 		angle along with the angular extent are the controlling factor
!B 		for the sphere around the axis.
!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 		in the XY plane.
!B
!B      PICK AXIS LINE: Pick the line to be used as the axis of the sphere.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: axis line sphere ")

DIM Destination$[256]
DIM Answer$[256]
DIM Radius_var$[256]
DIM Slen_var$[256]
DIM Elen_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Name$[256]
DIM Axis_line$[256]

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF
Astart= 0
Angle= 180

Stat= GLPLotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=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(-Radius)
Start_length=GetValue("STARTING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_slen_var= LastVariableInput(Slen_var$)


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Radius)
End_length=GetValue("ENDING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_elen_var= LastVariableInput(Elen_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


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Axis line sphere")
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
ELSE
        V1= FreeParameter("Radius",Radius_var$)
END IF
IF No_slen_var THEN
        V2= FreeParameter("Start Length",Start_Length)
ELSE
        V2= FreeParameter("Start Length",Slen_var$)
END IF
IF No_elen_var THEN
        V3= FreeParameter("End Length",End_Length)
ELSE
        V3= FreeParameter("End Length",Elen_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
C1=AxisLineSphere(Axis_line$,V1,V2,V3,V4,V5,Direction)
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("spherical sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

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