
! script name: property.d/tblpropdir
! topic: make an info packet class directory from a table

!A
!A NAME:
!A
!A 	Make Properties From Table
!A
!A DESCRIPTION:
!A
!A 	This script creates and fills a packet's class directory
!A 	with packets created from a table.
!A
!B INSTRUCTIONS:
!B
!B 	PACKET CLASS DIRECTORY: Select the class directory of the packet
!B 	or type in the name of a new directory.  You can also type in a
!B	directory name (or directory tree) that you would like to create.
!B
!B 	DIRECTORY EXISTS. OVERWRITE.  Yes, Delete, No: If the directory
!B	already exists this question will appear.
!B
!B		Yes-Saves all the packets in the table. Existing packets not
!B 		listed in the table are not deleted.
!B 		Delete-Deletes the directory.  Then saves all the packets.
!B 		The table represents all the packets in that directory.
!B 		No-Saves the packets that are new to that directory.
!B		Existing packets not listed in the table are not deleted.
!B
!B 	PACKET CLASS NAME: Enter the name of the packet class.  All packets
!B 	in the same class directory should have the same class name.
!B
!B 	CLASS ID NUMBER  (10000 - 100000)    Existing: Enter a packet class
!B 	ID number (any number from 10000 - 100000).  The packet class
!B 	ID number is a unique number assigned to each packet class.  Every
!B 	packet in a specific class must have the same class number.  Every
!B 	different class must have a different class ID number.  Only one
!B 	packet of a given class number can be associated with a Synergy entity,
!B 	however, many different classes may be associated with the same entity.
!B
!B 	PICK TABLE: Pick the table that you are going to use to create the
!B 	packet.  The entries in row one of the table become the datafield
!B 	names in your new packet. The entries in column one become the
!B 	corresponding packet names and packet file names.  The packet file
!B 	name is a modified version of the packet name taht creates a valid
!B 	file name.
!B
!# see also - property.d/property.hlp
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: make packet class from table")

DIM Answer$[512]
DIM A$[512]
DIM Class_name$[512]
DIM Class_dir$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Filename$[512]
DIM Descr$[512]
DIM Element$[512]
DIM Name$[512]
DIM Destination$[512]
DIM D_label$[512]
DIM Current_dir$[512]
DIM Ques$[512]
DIM Choice$[512]
DIM Sub_class$[512],Sub_class2$[512]
DEG


Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Class_directory:!
Start:!
D_label$="PACKET CLASSES"
Choice$="CLASS SELECTED"
Ques$= "PACKET CLASS DIRECTORY  List  "
Answer$= SelectDirectory(Prop_dir$,"*",Ques$,D_label$,Choice$,"",Current_dir$)
IF (ExitScript(Destination$)) THEN Leave
IF  Answer$= "CANCEL" THEN Leave
Answer$= TRIM$(Answer$)
Class_dir$= Answer$
Prop_class$= PathNameFile(Answer$)
IF NOT DoesFileExist(Class_dir$) THEN
	Create_dir= 1
	Delete_dir= 0
ELSE
	Create_dir= 0
	Delete_dir= 0
	Overwrite=1
	Stat=SetInputFormat("a1",",Y,N,D,")
	Stat=GetValue("DIRECTORY EXISTS. OVERWRITE  Yes, Delete, No ",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$= "N" THEN Overwrite=0
	IF Answer$= "D" THEN
		Delete_dir= 1
	END IF
END IF
LowerSelectBox

Name_loop:!
stat= SetInputFormat("a99","")
Stat=GetValue("PACKET CLASS NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Class_name$= Answer$

Ask_id_num:stat= SetInputFormat("n0a1",",E,")
Id_number= GetValue("CLASS ID NUMBER  (10000 - 100000)    Existing ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "E" THEN
        stat= PropClassNameList(Prop_dir$,":",2)
        GOTO Ask_id_num
END IF
IF Id_number< 10000 OR Id_number> 100000 THEN Ask_id_num


Pick_loop:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK TABLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Table1) THEN Pick_loop
T1= LastPickPara

IF Create_dir THEN
Next_class:!
	Sub_class2$= Class_dir$
Next_inst:Sub_class$= PathNameDirectory(Sub_class2$)
	IF DoesFileExist(Sub_class$) THEN
		CREATE DIR Sub_class2$
		IF Sub_class2$<>Class_dir$ THEN Next_class
	ELSE
		Sub_class2$= Sub_class$
		GOTO Next_inst
	END IF
ELSE
	IF Delete_dir THEN
		Stat= RemoveDirTree(Class_dir$)
		IF NOT DoesFileExist(Class_dir$) THEN
			CREATE DIR Class_dir$
		END IF
	END IF
END IF
Stat= PropDirFromTable(Table1,":",Class_dir$,Class_name$,Id_number,Overwrite)

GOTO Start

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

