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

!A
!A NAME:
!A
!A 	Tables: Make a table from a group of points.
!A
!A DESCRIPTION:
!A
!A	This script will make a table from a group of points.
!A
!B INSTRUCTIONS:
!B
!B	CATEGORY COLUMN NAME: Give the name of the column having the
!B				category name.
!B	
!B	CATEGORY NAME: This is the entry placed into the category column.
!B
!C NOTES:
!C
!C	It is also assumed the the x,y,z coordinates are in
!C	the columns labeled "X","Y","Z" respectively.
!C
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM A$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Table$[256]
DIM Group$[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$= "" 

Element_loop:!
stat= SetInputFormat("a1",",N,")
Table1=PickEntity("PICK TABLE, New ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="N" THEN
	Table$= ""
	New_table=1
ELSE
	IF NOT ValidDependency(Table1) THEN Element_loop
	Stat= EntityNameCheck(Table1,Table$)
	New_table=0
END IF


Pick_loop:!
stat= SetInputFormat("n4","")
Group=PickGroupEnt("PICK POINT GROUP")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Group) THEN Pick_loop
Stat= EntityNameCheck(Group,Group$)

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= AdvanceUndoNumber("pt group table")
IF New_table THEN
	Stat= GenerateVarName(WsDataTableEnt,Name$)
ELSE
	Stat= AddItemToUndo(WsUBModifyMode,Table$)
	Stat= EraseEntity(Table$)
END IF
RecordFunctionOn
Stat= RecordDescr("TABLE: point group table")
V1= FreeParameter("Type",1)
V2= StringConstant(Category$)
V3= StringConstant(Category_row$)
V4= StringConstant(Xrow$)
V5= StringConstant(Yrow$)
V6= StringConstant(Zrow$)
IF New_table THEN
	Table1= TableFromPtGroup(V1,0,Group$,V2,V3,V4,V5,V6)
	Stat= NameEntity(Table1,Name$)
ELSE
	Table1= TableFromPtGroup(V1,Table$,Group$,V2,V3,V4,V5,V6)
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

ActivateUndo
IF New_table THEN
	Stat= AddItemToUndo(WsUBCreateMode,Table1)
END IF
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start


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

