
! script name: vpksolids.d/vpksphere
! var_solids: construct a sphere in the current workplane

!A
!A NAME:
!A
!A 	Solid Sphere  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a sphere 
!A
!B INSTRUCTIONS:
!B
!B	RADIUS: Enter the radius if the sphere.
!B
!B	LOCATION POINT: Enter the location of the center of the sphere.
!B
!# see also - htdocs/help.d/parasolids.htm

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Center$[256]
DIM Radius_var$[256]


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

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

Stat= GLPlotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R1)
R1=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

Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("LOCATION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SPHERE: Solid")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_radius_var THEN
        V1= FreeParameter("Radius",R1)
        C1=WPKSphere(Pc,V1)
ELSE
        C1=WPKSphere(Pc,Radius_var$)
END IF
Stat= WPKNameBody(C1,Name$)
Stat= WPKSetBodyParent(C1)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("solid sphere")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
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
