
! script name: points.d/gridpoints
! topic: create grid pattern of points

!A 
!A NAME:
!A
!A 	Grid Points
!A
!A DESCRIPTION:
!A
!A 	This script creates a grid pattern of points.
!A
!A~ image location - images/pointgrid.jpg
!B INSTRUCTIONS:
!B
!B 	NUMBER OF POINTS IN A LINE: Enter the number of points that
!B 		should occur in each line.
!B
!B 	ANGLE OF LINE OF POINTS: Enter the angle of the line the points
!B 		should be constructed along.
!B
!B 	SPACING BETWEEN POINTS: Enter the distance between the
!B 		points along the line.
!B
!B 	NUMBER OF LINES OF POINTS: Enter the number of lines of
!B 		points that should be created at this angle.
!B
!B 	   NOTE: If there are more than one line of points to be created the
!B 		 following TWO questions will also be asked.
!B
!B 	   X SPACING BETWEEN LINES: Enter the distance that the lines
!B 		of points should be spaced in X.
!B
!B 	   Y SPACING BETWEEN LINES: ENTER the distance that the lines
!B 		of points 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.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: grid points ")

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

ActivateUndo
Grid_loop:!

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,0,0)
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
Stat=SetLastPoint(Pc)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Xvector)
Stat=DeleteEntity(Yvector)

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

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
