
! script name: vpoints.d/boltcircle
! var_topic: create partial or full circular pattern of points

!A
!A NAME:
!A
!A 	Bolt Hole Circle	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a partial or full circular pattern of points.
!A
!A~ image location - images/boltcircle.jpg
!B INSTRUCTIONS:
!B
!B 	BOLT HOLE RADIUS: Enter the radius to be used for the
!B 		circular pattern.
!B
!B 	BOLT HOLE CENTER ABS X,Y: Enter the X,Y coordinates of
!B 		the center of the circular pattern.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	STARTING ANGLE: Enter the angle to the first point of
!B 		the pattern.
!B
!B 	NUMBER OF POINTS: Enter the number of points to be
!B 		constructed.
!B
!B 	Full or Partial BOLT CIRCLE: Enter "F" for full or "P" for partial
!B 		to indicate which type should be created.
!B
!B 	NOTE: If partial is selected the following question will be asked.
!B
!B 	ANGULAR INCREMENT: Enter the number of degrees between
!B 		the points.  The angular increment will be calculated
!B 		automatically for a full bolt hole circle.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: bolt hole circle ")

DIM Answer$[256]
DIM Destination$[256]
DIM Bolt_hole$[256]
DIM Center$[256]
DIM Radius_var$[256]
DIM Angle_var$[256]
DIM Astart_var$[256]
DIM Num_points$[256]
DEG

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Radiusr=NamedVarVal("bolt hole radius",WsPointVars,1.0)
Stat=SetRadiusEquals(Radiusr)

Bolt_loop:Stat=SetInputFormat("n4=","")
Radius=InputRadius("BOLT HOLE RADIUS")
IF (ExitScript(Destination$)) THEN Leave
Radiusr=Radius
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Circle_loop
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF
Vradius=CreateVariable("bolt hole radius",WsPointVars,Radiusr)

Center_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK BOLT HOLE CENTER")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Center_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetLastPoint(Pc)
Stat=DeleteEntity(Pc,WsTrue)

stat= SetAngleEquals(0)
Astart=InputAngle("STARTING ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)

Stat=SetInputFormat("n0","")
Num_pts=GetValue("NUMBER OF POINTS",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_num_var= LastVariableInput(Num_points$)

Stat=SetInputFormat("a1=",",F,P,")
Stat= SetEqualsValue(0,"F")
Stat=GetValue("Full or Partial BOLT CIRCLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

IF (Answer$="P") THEN
	Full=WsPartial
ELSE
	Full=WsFull
END IF

Ang_inc=0
Stat=SetInputFormat("n4","")

IF (Full=WsPartial) THEN
	Ang_inc=InputAngle("ANGULAR INCREMENT BETWEEN POINTS")
	IF (ExitScript(Destination$)) THEN Leave
END IF

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("GROUP: Bolt circle")
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("Starting angle",Astart)
ELSE
	V2= FreeParameter("Starting angle",Astart_var$)
END IF
IF No_num_var THEN
	V4= FreeParameter("Number points",Num_pts)
ELSE
	V4= FreeParameter("Number points",Num_points$)
END IF
IF (Full=WsPartial) THEN
	V3= FreeParameter("Angle increment",Ang_inc)
	G1=BoltHole(V1,Pc,V2,V3,V4,WsPartial,0,0)
ELSE
	G1=BoltHole(V1,Pc,V2,0,V4,WsFull,0,0)
END IF
Stat= AutoNameGroup(G1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Center$)

ActivateUndo
Stat= AdvanceUndoNumber("bolt circle")
Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsFalse)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Bolt_loop

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