
! script name: vdatatable.d/rowpointgrp
! var_topic: make a group of points from rows in a table.

!A
!A NAME:
!A
!A 	Tables: Make a group of points from rows in a table. VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will make a group of points from rows in a table.
!A	A category name may be specified to use an additional column
!A	as a filter for selecting the points.
!A
!A~ image location - images/pointtable.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK START TABLE ROW: Pick the starting table row to be used. If 
!B				changed to zero it will assume row 2.
!B
!B 	PICK END TABLE ROW: Pick the ending table row to be used. If 
!B				changed to zero it will assume the last row.
!B
!B	CATEGORY COLUMN NAME: Give the name of the column having the
!B				category name.
!B	
!B	CATEGORY NAME: Name used for selecting only the points in
!B			the table which match the category.
!B
!B
!C NOTES:
!C	It is assumed in the script that the points will be
!C	created on the current workplane with coordinates relative to
!C	that workplane.
!C
!C	It is also assumed the the x,y,z coordinates are in
!C	the columns labeled "X","Y","Z" respectively.
!C
!C	The z coordinate is optional it will default to zero
!C	if it is absent.
!C
!C	A non numeric symbol in a column will cause that point
!C	coordinate to use the previous table value.
!C
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: table row point group ")

DIM Answer$[256]
DIM A$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DIM Xrow$[256]
DIM Yrow$[256]
DIM Zrow$[256]
DIM Category$[256]
DIM Category_row$[256]
DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Start:!
Ask_category=1
Xrow$= "X" 
Yrow$= "Y" 
Zrow$= "Z" 
Category_row$= "" 
Category$= "" 


Pick_loop:!
stat= SetInputFormat("n4","")
Table=PickEntity("PICK STARTING TABLE ROW ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Table,Element$)

R1=TableParaRow(Table,T1)
C1=TableParaColumn(Table,T1)

stat= SetInputFormat("n4","")
Table=PickEntity("PICK ENDING TABLE ROW ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Table,Element$)

R2=TableParaRow(Table,T1)
C2=TableParaColumn(Table,T1)

IF Ask_category THEN
	Stat=SetInputFormat("a99","")
	Stat=GetValue("CATEGORY COLUMN NAME, None ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	A$= UPC$(Answer$)
	IF A$= "NONE" OR A$="N" THEN
		Category_row$= ""
	ELSE
		Category_row$= Answer$
	END IF
	IF LEN(Category_row$) THEN
		Stat=SetInputFormat("a99","")
       		Stat=GetValue("CATEGORY NAME ",Answer$)
       		IF ExitScript(Destination$) THEN Leave
		Category$= Answer$
	END IF
END IF

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("GROUP: Table row point group")
V1= FreeParameter("Start row",R1)
V2= FreeParameter("End row",R2)
V3= StringConstant(Category$)
V4= StringConstant(Category_row$)
V5= StringConstant(Xrow$)
V6= StringConstant(Yrow$)
V7= StringConstant(Zrow$)
G1= TableRowPtGroup(Element$,V1,V2,V3,V4,V5,V6,V7)
Stat= AutoNameGroup(G1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("row point group")
Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsFalse)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start


Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

