
! script name: vproperty.d/extfieldentry
! var_topic: copy an external info packet field into a table entry

!A
!A NAME:
!A
!A 	Entry from External Field
!A
!A DESCRIPTION:
!A
!A 	An external info packet field is an info packet that is not currently 
!A 	being used as an info packet entity. It remains external to the program
!A 	as an ASCII data file.  This script will take a data field in an
!A 	external info packet and place it in a table entry position. This way
!A 	you can use your data in info packets that may not currently be
!A 	attached to geometry. The data may either be string or numeric. If the
!A 	field contains valid numeric data it will be interpreted as a numeric
!A 	table entry, otherwise it will be treated as a string entry.
!A
!B INSTRUCTIONS:
!B
!B 	INFO PACKET CLASS DIRECTORY: Select the info packet's class directory.
!B
!B 	EXISTING INFO PACKET FILE NAME: Pick the info packet file from the
!B 	selection box.
!B
!B 	SELECT DATA FIELD: Pick the data field from the selection box.
!B
!B 	PICK ENTRY POSITION: Pick the row column position in the table.
!B
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: external property field table entry ")

DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM Name$[512]
DIM Table$[512]
DIM Descr$[512]
DIM Element$[512]
DIM Destination$[512]
DIM Prop_name$[512]
DIM Field$[512]
DIM Namelist$[32000]
DIM Field_id$[512]
DIM Field_data$[512]
DIM D_label$[512]
DIM Choice$[512]
DIM Format$[512]
DIM Filename$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Prop_dir$[512]
DIM Prop_file$[512]
DIM Current_dir$[512]
DIM Ques$[512]
DEG

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

A= GetDefault(WsPlacesAfter)
Format$= "decimal "&VAL$(A)


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


Start:!
DeActivateUndo

Ask_class:!
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$=  BaseNamePath(Answer$,Prop_dir$)
Prop_class$= PathNameFile(Answer$)

Ask_file:!
D_label$= Prop_class$
Choice$= Prop_class$&" SELECTED"
Stat= DirListBox(FileNameString(Prop_dir$,Class_dir$),"*",D_label$,Choice$,WsAscending)

File_name:stat= SetInputFormat("a99","")
stat= GetValue("PACKET FILE NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
IF NOT LEN(Answer$) THEN File_name
Prop_file$= Answer$
Filename$= FileNameString(Prop_dir$,Class_dir$,Prop_file$)

Get_prop_file:!
Id_number=GetExtUserValue(Filename$,"Class id number:")
Prop_name$= ExtUserDataStr(Filename$,"Name:")
Prop_ent= ReadUserData(Id_number,Prop_name$,Filename$)

List_fields:!
Namelist$= DataFieldListStr(Prop_ent,":",",",WsNoOrder,WsTrue)
D_label$="DATA FIELDS"
Choice$="DATA FIELD SELECTED"
Stat=GeneralListBox(D_label$,Choice$,Namelist$)

Data_field:stat= SetInputFormat("a99","")
stat= GetValue("SELECT DATA FIELD",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Data_field
LowerSelectBox
SELECT Answer$
CASE "CANCEL"
        GOTO Start
END SELECT
IF POS(Answer$,"=") THEN
        Field_id$= DataFieldStr(Answer$,"=",1)
        Field_id$= Field_id$&":"
        Field_data$= DataFieldStr(Answer$,"=",2)
        Field_data$= TRIM$(Field_data$)

ELSE
        Field_data$=""
END IF

Pick_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK ENTRY POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Element1,Table$)
R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Make_entry:!
IF IsStringNumeric(Field_data$) THEN
	Numeric_entry=1
ELSE
	Numeric_entry=0
END IF

A$= UserDataStr(Prop_ent,"Class name:")
B$=UserDataStr(Prop_ent,"Name:")
Descr$= "TABLE ENTRY: "&A$&":"&B$&":"&Field_id$
Stat= DeleteEntity(Prop_ent)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr(Descr$)
V1= StringConstant(Prop_dir$)
V2= StringConstant(Class_dir$)
V3= StringConstant(Prop_file$)
V4= StringConstant(FileNameString(V1,V2,V3))
Prop_ent= ReadUserData(WsMiscData," ",V4,WsTrue)
V1= StringConstant(Field_id$)
V2= FreeParameter("Row",R1)
V3= FreeParameter("Column",C1)
IF Numeric_entry THEN
	V4= StringConstant(Format$)
	Stat= DataValIntoTable(Table$,Prop_ent,V1,V4,V2,V3)
ELSE
	Stat= DataStrIntoTable(Table$,Prop_ent,V1,V2,V3)
END IF
Stat= DeleteEntity(Prop_ent)
RecordFunctionOff
CloseVarRecord
Stat= PlotEntity(Element1)

GOTO Get_prop_file



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

