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

!A 
!A NAME:
!A
!A 	Grid Points  VARIATIONAL
!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
!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 along.
!B
!B 	SPACING BETWEEN POINTS: Enter the distance between
!B 		the 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
!B 		 the 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.  NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Center$[256]
DIM Xspace_var$[256]
DIM Yspace_var$[256]
DIM Space_var$[256]
DIM Angle_var$[256]
DIM Num_points$[256]
DIM Num_lines$[256]
DEG

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Grid_loop:!

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

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

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

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

IF (Num_lines>1) THEN

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

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

ELSE

	Xspace=0
	Yspace=0
	No_xspace_var=1
	No_yspace_var=1

END IF

Center_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK GRID START POINT")
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= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("GROUP: Point grid")
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_npts_var THEN
        V1= FreeParameter("Number points in a line",Num_pts)
ELSE
        V1= FreeParameter("Number points in a line",Num_points$)
END IF
IF No_angle_var THEN
        V2= FreeParameter("Angle of line of points",Angle)
ELSE
        V2= FreeParameter("Angle of line of points",Angle_var$)
END IF
IF No_space_var THEN
        V3= FreeParameter("Spacing between points",Space)
ELSE
        V3= FreeParameter("Spacing between points",Space_var$)
END IF
IF No_nlines_var THEN
        V4= FreeParameter("Number lines of points",Num_lines)
ELSE
        V4= FreeParameter("Number lines of points",Num_lines$)
END IF
IF No_xspace_var THEN
        V5= FreeParameter("X line spacing ",Xspace)
ELSE
        V5= FreeParameter("X line spacing ",Xspace_var$)
END IF
IF No_yspace_var THEN
        V6= FreeParameter("Y line spacing",Yspace)
ELSE
        V6= FreeParameter("Y line spacing",Yspace_var$)
END IF
Xvector= PointPolar(V3,V2,0)
Yvector=PointXYZ(V5,V6,0)
G1=GridPoints(Pc,Xvector,Yvector,V1,V4,0,0)
Stat= AutoNameGroup(G1,Name$)
Stat= DeleteEntityList(Pc,Xvector,Yvector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Center$)
Stat= PlotEntity(Name$)

ActivateUndo
Stat= AdvanceUndoNumber("point grid")
Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsFalse)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Grid_loop

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