Jump to content
The Hamma

How do I make a script to edit every symbol in resource browser

Recommended Posts

The following script writes back the records to the matching symbol from a symbol that have been edited in a the drawing.  The problem is that it only works on the symbols in the root of the resource browser but does not work on symbols that are in folders.  How do I make this script edit every symbol in the resource browser for the current drawing?

 

{$DEBUG}
PROCEDURE ItemRecordtosymbol;
VAR
   countObj : INTEGER;
   lts,it1 : INTEGER;
   s3,itemname,grabsymbol,rITEM,rDESCRIPTION,rMANUFACTURER,rMODEL,rFURNISHEDBY,rINSTALLEDBY,rFLAMPS,rKW,rHP,rVOLTS,rPHASE,rDIRECTPOWER,rPLUG,rFILTERED,rCOLD,rHOT,rDIRECTWASTE,rINDERECTWASTE,rSIZE,rMBTUH,rREMARKS,rITEMGROUP,rREVISION:string;
   h,H1:handle;

PROCEDURE ExplodeSymbols(h :HANDLE);
BEGIN
	rITEM := GetRField(h,'ITEM','ITEM');
	rDESCRIPTION := GetRField(h,'ITEM','DESCRIPTION');
	rMANUFACTURER := GetRField(h,'ITEM','MANUFACTURER');
	rMODEL := GetRField(h,'ITEM','MODEL');
	rFURNISHEDBY := GetRField(h,'ITEM','FURNISHED BY');
	rINSTALLEDBY := GetRField(h,'ITEM','INSTALLED BY');
	rFLAMPS := GetRField(h,'ITEM','FL-AMPS');
	rKW := GetRField(h,'ITEM','KW');
	rHP := GetRField(h,'ITEM','HP');
	rVOLTS := GetRField(h,'ITEM','VOLTS');
	rPHASE := GetRField(h,'ITEM','PHASE');
	rDIRECTPOWER := GetRField(h,'ITEM','DIRECT POWER');
	rPLUG := GetRField(h,'ITEM','PLUG');
	rFILTERED := GetRField(h,'ITEM','FILTERED');
	rCOLD := GetRField(h,'ITEM','COLD');
	rHOT := GetRField(h,'ITEM','HOT');
	rDIRECTWASTE := GetRField(h,'ITEM','DIRECT WASTE');
	rINDERECTWASTE:= GetRField(h,'ITEM','INDIRECT WASTE');
	rSIZE:= GetRField(h,'ITEM','SIZE');
	rMBTUH:= GetRField(h,'ITEM','MBTUH');
	rREMARKS:= GetRField(h,'ITEM','REMARKS');
	rITEMGROUP:= GetRField(h,'ITEM','ITEM GROUP');
	rREVISION:= GetRField(h,'ITEM','REVISION');
END;



Begin
H1:=FSymDef;
While H1 <> Nil do
 Begin
       	itemname := GetName(H1);
		ForEachObject(ExplodeSymbols,((INSYMBOL & INOBJECT & INVIEWPORT & (T=SYMBOL) & (S=itemname))));
		SetRField(H1,'ITEM','ITEM',rITEM);
		SetRField(H1,'ITEM','DESCRIPTION',rDESCRIPTION);
		SetRField(H1,'ITEM','MANUFACTURER',rMANUFACTURER );
		SetRField(H1,'ITEM','MODEL',rMODEL);
		SetRField(H1,'ITEM','FURNISHED BY',rFURNISHEDBY );
		SetRField(H1,'ITEM','INSTALLED BY',rINSTALLEDBY );
		SetRField(H1,'ITEM','FL-AMPS',rFLAMPS );
		SetRField(H1,'ITEM','KW',rKW );
		SetRField(H1,'ITEM','HP',rHP );
		SetRField(H1,'ITEM','VOLTS',rVOLTS );
		SetRField(H1,'ITEM','PHASE',rPHASE );
		SetRField(H1,'ITEM','DIRECT POWER',rDIRECTPOWER );
		SetRField(H1,'ITEM','PLUG',rPLUG );
		SetRField(H1,'ITEM','FILTERED',rFILTERED );
		SetRField(H1,'ITEM','COLD',rCOLD );
		SetRField(H1,'ITEM','HOT',rHOT );
		SetRField(H1,'ITEM','DIRECT WASTE',rDIRECTWASTE );
		SetRField(H1,'ITEM','INDIRECT WASTE',rINDERECTWASTE);
		SetRField(H1,'ITEM','SIZE',rSIZE);
		SetRField(H1,'ITEM','MBTUH',rMBTUH);
		SetRField(H1,'ITEM','REMARKS',rREMARKS);
		SetRField(H1,'ITEM','ITEM GROUP',rITEMGROUP);
		SetRField(H1,'ITEM','REVISION',rREVISION);
   H1:=NextObj(H1);
 End;
End;

Run(ItemRecordtosymbol);

 

Share this post


Link to post

Using ForEachObjectInList() instead of iterating with NextObj() is the easiest method (choosing the descend into groups option).

 

Otherwise, make your while statement into a function. At the top of the function, check if the type of H1 is a symbol folder, and if so, call the function (recursively) on FInGroup(H1). Otherwise, process the symbol.

Share this post


Link to post

Do you really intend to store the data from a single symbol instance into EVERY symbol definition in the drawing?

Share this post


Link to post
1 hour ago, JBenghiat said:

Using ForEachObjectInList() instead of iterating with NextObj() is the easiest method (choosing the descend into groups option).

 

Otherwise, make your while statement into a function. At the top of the function, check if the type of H1 is a symbol folder, and if so, call the function (recursively) on FInGroup(H1). Otherwise, process the symbol.

 

I will give that a try, thank you. 

 

1 hour ago, Pat Stanford said:

Do you really intend to store the data from a single symbol instance into EVERY symbol definition in the drawing?

 

I did revise it t a bit since I posted i but it cycles through the list of symbols in the resource browser and looks for the matching symbol in the drawing. When it finds it if it has the 'ITEM' record it copies the values from the symbol in the drawing and rewrites the values to the matching symbol in the resource browser.  I am using this because I have a customer that reuses equipment over and over but sometimes it gets revised.  I have an equipment schedule that pulls the info from the symbols in the drawing.  I am writing this script because if you edit the record on the symbol or from the schedule the record attached to the symbol in the resource browser is not updated by that edit.  This script will update the resource browser.  

Share this post


Link to post

I think that is the hard way to do it.

 

GetObject(GetSymName(H1)); should get you a handle to the symbol. I don't have VW open right now. Test it and see if GetType of the handle returned by GetObject isn't a Symbol Def.

Share this post


Link to post

Ah, this is just the function I have been looking for. I would even go so far as to suggest something similar, matching user defined record formats, might be made available in a general utility menu/tool from Vectorworks for those of us who have to manage large object libraries (with all the necessary overwrite warnings etc).

 

Multiple Symbol DEFINITION access is essential with the volume of data required for BIM today.

Share this post


Link to post

This can also be done relatively easily.

 

FSymDef returns a Handle to the first Symbol Definition in the file. You can then use NextObject to step through all of the symbol definitions and check for a specific record and edit as appropriate.

 

Let me know if you need a sample script.

Share this post


Link to post
On 9/29/2020 at 11:55 AM, Pat Stanford said:

This can also be done relatively easily.

 

FSymDef returns a Handle to the first Symbol Definition in the file. You can then use NextObject to step through all of the symbol definitions and check for a specific record and edit as appropriate.

 

Let me know if you need a sample script.

 

Though to answer the original question, you still have to dive into symbol folders when you find them.

 

ForEachObjectInList(), passing FSymDef as the first object, will iterate through symbols and symbol folders — you just need to get the type of each object to check if it is a symbol before handling.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...