
! script name: holes.d/hgridpoints
! topic: create grid pattern of holes

!A
!A NAME:
!A
!A 	Grid of Holes
!A
!A DESCRIPTION:
!A
!A 	This script creates a grid pattern of holes.
!A
!B INSTRUCTIONS:
!B
!B 	HOLE DIAMETER: Enter the diameter of the hole to be constructed.
!B
!B 	FINISH DEPTH: Enter the depth of the hole to be constructed.
!B
!B 	NUMBER OF POINTS IN A LINE: Enter the number of points
!B 		that should occur in each line.
!B
!B 	ANGLE OF LINE OF POINTS: Enter the angle of the line
!B 		the points should be constructed on.
!B
!B 	SPACING BETWEEN POINTS: Enter the distance that the
!B 		points should be spaced.
!B
!B 	NUMBER OF LINES OF POINTS: Enter the number of lines
!B 		of points that should be created at this angle.
!B
!B 		NOTE: If there are more than one line of points to be
!B 		created the following TWO questions will also be asked.
!B
!B 	X SPACING BETWEEN LINES: Enter the distance that the points
!B 		should be spaced in X.
!B
!B 	Y SPACING BETWEEN LINES: Enter the distance that the points
!B 		should be spaced in Y.
!B
!B 	GRID START POINT ABS X,Y: Enter the X,Y coordinates of the
!B 		start point of the grid pattern.  NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: grid of holes ")

DIM Answer$[256]
DIM Destination$[256]
DIM Grid_hole$[256]
DEG

ActivateUndo
Grid_loop:!

Stat=SetInputFormat("n4=","")
Diar=NamedVarVal("hole diameter",WsPointVars,0.0)
Stat=SetRadiusEquals(Diar/2)

Dia=InputRadius("HOLE DIAMETER",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
Diar=Dia

Vdia=CreateVariable("hole diameter",WsPointVars,Diar)

Depthr=NamedVarVal("hole depth",WsPointVars,0.0)
Stat=SetDepthEquals(Depthr)

Depth=InputDepth("FINISH DEPTH")
IF (ExitScript(Destination$)) THEN Leave
Depthr=Depth

Vdepth=CreateVariable("hole depth",WsPointVars,Depthr)

Stat=SetPickReturn(WsHoleXYZ)


Stat=SetInputFormat("n0","")
Num_pts=GetValue("NUMBER OF POINTS IN A LINE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Angle=InputAngle("ANGLE OF LINE OF POINTS")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4","")
Space=GetValue("SPACING BETWEEN POINTS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n0","")
Num_lines=GetValue("NUMBER OF LINES OF POINTS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

IF (Num_lines>1) THEN

	Stat=SetInputFormat("n4","")
	Xspace=GetValue("X SPACING BETWEEN LINES",Answer$)
	IF (ExitScript(Destination$)) THEN Leave

	Yspace=GetValue("Y SPACING BETWEEN LINES",Answer$)
	IF (ExitScript(Destination$)) THEN Leave

ELSE

	Xspace=0
	Yspace=0

END IF

Stat=SetInputFormat("n4=","")
Pc=XyzInput("GRID START POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

Xvector=PointXYZ(Space*COS(Angle),Space*SIN(Angle),0)
Yvector=PointXYZ(Xspace,Yspace,0)

Group=GridPoints(Pc,Xvector,Yvector,Num_pts,Num_lines,Dia,Depth)
IF ValidGeometry(Group) THEN
   Grid_group=CurrHoleGrpNum
   Grid_hole$="GRID"&VAL$(Grid_group)
   Stat=ChangeGrpName(Group,Grid_hole$)
   Grid_group=Grid_group+1
   Stat=SetHoleGrpNum(Grid_group)
END IF

ActivateUndo
Stat= AdvanceUndoNumber("hole grid")
Stat= AddGroupToUndo(WsUBCreateMode,Group,1,WsFalse)


Stat=SetLastPoint(Pc)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Xvector)
Stat=DeleteEntity(Yvector)

GOTO Grid_loop

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