
! script name: vsolids.d/normaldisk
! var_topic: construct plane normal to a curve element

!A
!A NAME:
!A
!A 	Disk: Normal disk to curve element  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a disk of specified radius, astart,angle, 
!A 	normal to an entity at a point.
!A
!B INSTRUCTIONS:
!B
!B 	DISK RADIUS: Enter the radius of the disk to be constructed.
!B
!B 	STARTING ANGLE: Enter the starting angle of the disk.
!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 	PICK NORMAL ELEMENT: Pick the element that defines the disk normal.
!B
!C NOTES:
!C
!C 	The U contours of a disk are the circles and the V contours are the
!C 	radial lines.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: normal disk ")

DIM Destination$[256]
DIM Answer$[256]
DIM Radius_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Tilt_var$[256]
DIM Name$[256]
DIM Element$[256]
DIM Center$[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


Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("DISK 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=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$)


Stat=SetAngleEquals(Tilt_angle)
Tilt_angle=InputAngle("TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_tilt_var= LastVariableInput(tilt_var$)


Pick_loop:Stat=SetInputFormat("n4","")
Stat=SetPickMask(WsPickNoSurf)
E1=PickEntity("PICK NORMAL ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
Stat= EntityNameCheck(E1,Element$)
Stat=SetPickMask(WsPickAll)


Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK POINT ON ENTITY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)


On_center=1
Stat= GenerateVarName(WsDiskSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("DISK: Normal to entity")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
ELSE
        V1= FreeParameter("Radius",Radius_var$)
END IF
IF No_astart_var THEN
        V2= FreeParameter("Astart",Astart)
ELSE
        V2= FreeParameter("Astart",Astart_var$)
END IF
IF No_angle_var THEN
        V3= FreeParameter("Angle",Angle)
ELSE
        V3= FreeParameter("Angle",Angle_var$)
END IF
IF No_tilt_var THEN
        V4= FreeParameter("Tilt Angle",Tilt_angle)
ELSE
        V4= FreeParameter("Tilt Angle",Tilt_var$)
END IF
Axis_line=TangentLine(Element$,Pc,WsTRIMMED)
D1=AxisLineDisk(Axis_line,V1,V2,V3,V4,WsForward)
Stat= NameEntity(D1,Name$)
Stat= DeleteEntityList(Axis_line,Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(D1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("disk")
	Stat= AddItemToUndo(WsUBCreateMode,D1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_loop

Leave:!
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Pt)
Stat= DeleteEntity(Axis_line)

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