
! script name: vsolids.d/cirsphere
! var_topic: construct sphere defined by circle, start length, and end length

!A
!A NAME:
!A
!A 	Sphere: Circle	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a sphere or a part of a sphere, using the
!A 	picked circle as the reference for the center of the sphere.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CIRCLE: Pick the circle to be used as the reference for the
!B 		center of the sphere.
!B
!B 	STARTING LENGTH: Enter the controlling extent of the sphere along
!B 		the axis, negative measures backward from the starting point,
!B 		zero 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
!C NOTES:
!C
!C 	The U contours of a sphere are the circles from the starting length
!C 	to the ending length.  The V contours of a sphere are the circles 
!C 	formed from the starting angle to the ending angle.
!C

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

DIM Destination$[256]
DIM Answer$[256]
DIM Slength$[256]
DIM Elength$[256]
DIM Circle$[256]
DIM Name$[256]


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


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$)

Radius=CircleRadius(pcircle)
Radius=ABS(Radius)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(-Radius)
Start_length=GetValue("STARTING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_slength_var= LastVariableInput(Slength$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Radius)
End_length=GetValue("ENDING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_elength_var= LastVariableInput(Elength$)

Stat= GenerateVarName(WsSphereSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SPHERE: Circle")
Stat= SetRecDelLastExec
IF No_slength_var THEN
        V1= FreeParameter("Start Length",Start_length)
ELSE
        V1= FreeParameter("Start Length",Slength$)
END IF
IF No_elength_var THEN
        V2= FreeParameter("End Length",End_length)
ELSE
        V2= FreeParameter("End Length",Elength$)
END IF
S1=CircleSphere(Circle$,V1,V2)
Stat= NameEntity(S1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("sphere")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Cloop

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