
! script name: property.d/attachinbox
! topic: attach an info packet to entities in a box

!A
!A NAME:
!A
!A	Attach In Box
!A
!A DESCRIPTION:
!A
!A 	You might want the information in your info packet to apply to
!A 	several entities.  Consider the geometry that makes up a contour
!A 	or a tool path.  It would be easier to have the info packet
!A 	associated with the entire contour, rather than with just one of
!A 	the geometric components. You can drag a selection box across the
!A 	geometry that makes up the contour, and then attach an info packet
!A 	to it.  This script will associate an info packet with the entities
!A 	you frame in a selection box.
!A
!B INSTRUCTIONS:
!B
!B 	Select the entities by clicking and dragging diagonally across the
!B 	entities that you want the packet attached to.
!B
!B 	Existing info packets are displayed in a select box.
!B 	The list shows the packets' class followed by the packets' name.
!B
!B 	If you select the "CANCEL" button, the packet Class Menu will be
!B 	displayed and you may select a new packet class and name.
!B
!C NOTES:
!C
!C 	Synergy optimizes info packets as best as it can.  If an imported
!C 	packet is identical to an existing packet then Synergy will use the
!C 	existing one.
!C
!C 	Duplicate packets may be removed by running the cleanup script.
!C
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: attach packet in box")

DIM Destination$[512]
DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM Name$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Class_name$[512]
DIM Filename$[512]
DIM Oldname$[512]
DIM Data$[32000]
DIM D_label$[512]
DIM Sub_label$[512]
DIM F_label$[512]
DIM Choice$[512]
DIM Mask$[32]
DIM Current_dir$[512]
DIM Ques$[512]

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

DeActivateUndo
Start:!
Existing_props:!
Group= GrpOfUserProps
IF NOT GroupCount(Group) THEN New_prop
Stat=UserSelectBox("EXISTING INFO PACKETS","Packet selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT INFO PACKET NAME",Name$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Name$
CASE "CANCEL"
	Stat= DeleteEntity(Group)
	GOTO New_prop
END SELECT

Num1= NumericPrefix(Name$)
IF NOT Num1 THEN Pick_prop
Prop_ent= GroupElement(Group,Num1)
IF NOT ValidGeometry(Prop_ent) THEN Start
Stat= DeleteEntity(Group)
LowerSelectBox
GOTO Pick_entity


New_prop:!
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$)


Ask_file:!
D_label$= Prop_class$
Choice$= Prop_class$&" SELECTED"
Stat=DirListBox(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
Oldname$= Answer$
Filename$= FileNameString(Class_dir$,Oldname$)

Id_number=GetExtUserValue(Filename$,"Class id number:")
Stat=GetExtUserString(Filename$,"Name:",Name$)
P1= ReadUserData(Id_number,Name$,Filename$)
Prop_ent= ResolveDupUserProp(P1)
LowerSelectBox


Pick_entity:!
Group=CreateGroup("TEMPGROUP")

Vnum=PickView("SELECT VIEW FOR SELECTION BOX")
IF (ExitScript(Destination$)) THEN Leave
Stat=PickBox(Group,Vnum,WsHighlightPen)
IF (ExitScript(Destination$)) THEN Leave

IF NOT GroupCount(Group) THEN 
	Stat=DeleteEntity(Group)
	GOTO Start
END IF

Stat=Highlight(Group,WsPickPen,WsDirArrowOff)
Id_number=GetUserValue(Prop_ent,"Class id number:")
Stat=AssocUserData(Group,Prop_ent,Id_number)
Stat=DeleteEntity(Group)

GOTO Pick_entity

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


