
! script name: vlist.d/listentrefs
! var_topic: list entity references 

!A
!A NAME:
!A
!A      LIST Entity References
!A
!A DESCRIPTION:
!A
!A 	This script will create a list of the entity references.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY, Name: Pick the entity to be used as the reference for
!B 		the list, or select "N" to enter the name of the entity.
!B
!B 	ENTITY NAME: Enter the name of the entity to be used as the
!B 		reference for the list.  This question is only asked if
!B 		the name option was selected.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: list entity references")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Object_name$[256]
DIM Descr$[256]
DIM File$[256]
DIM Title$[256]
DIM Vdata$[32000]
DIM A$[256]

Global_color=3
Local_color=4
Highlight_color=2
File$="tempdata"

Start:!
Pick_entity:!
stat= SetInputFormat("n4a1",",N,")
E1=PickEntity("PICK ENTITY, Name ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "N" THEN
Entity_name:Stat=SetInputFormat("a99","")
	Stat=GetValue("ENTITY NAME",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	E1=FindNamedEntity(Answer$)
	IF NOT ValidGeometry(E1) THEN Entity_name
	Stat=SetInputFormat("n4","")
END IF

Title$= "Entity Reference"
Stat= OutputString(File$,CHR$(10),WsNewFile)
Stat= ReadEntityName(E1,Name$)
IF LEN(Name$) THEN
	A$= "NAME:   "&Name$
	stat= OutputString(File$,A$&CHR$(10),WsAppend)
	stat= OutputString(File$,CHR$(10),WsAppend)
END IF

Group= EntReferenceGroup(E1)
IF NOT ValidGeometry(Group) THEN 
	stat= OutputString(File$,"NO DIRECT REFERENCES "&CHR$(10),WsAppend)
	Stat= OutputString(File$,CHR$(10),WsAppend)
	Stat= MessageFileBox(File$,Title$)
	GOTO Pick_entity
END IF

Object_name$=""
N1= GroupCount(Group)
FOR I= 1 TO N1
	Var_record= GroupElement(Group,I)
	Var_object= VarObjectParent(Var_record)
	Rec_num= VarRecordNumber(Var_record)
	stat= GetDescription(Var_record,Descr$)
	stat= VarRecordData(Var_record,Vdata$)
	Stat= VarObjectName(Var_object,Name$)

	IF Name$<> Object_name$ THEN
		Stat= OutputString(File$,"OBJECT:       "&Name$&CHR$(10),WsAppend)
		Stat= OutputString(File$,CHR$(10),WsAppend)
		Object_name$= Name$
	END IF

	Stat= OutputString(File$,"RECORD #: "&VAL$(Rec_num)&CHR$(10),WsAppend)
	Stat= OutputString(File$,"DESCRIPTION: "&Descr$&CHR$(10),WsAppend)
	Stat= OutputString(File$,Vdata$,WsAppend)
	Stat= OutputString(File$,CHR$(10),WsAppend)
NEXT I
Stat= OutputString(File$,CHR$(10),WsAppend)
Stat= MessageFileBox(File$,Title$)

Stat= DeleteEntity(Group)


GOTO Pick_entity


Leave:!


IF (NOT LEN(Destination$)) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
