Jump to content
Developer Wiki and Function Reference Links ×

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


The Hamma

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);

 

Link to comment

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.

Link to comment
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.  

Link to comment

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.

Link to comment
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.

Link to comment
  • 4 months later...

Man, you are making me really go back in the archive.

 

This script sets all symbols in the resource manager to insert as groups. This is from 2007.

Procedure SetSymbolsToInsertAsGroups;
{Copyright 2007, Coviana Inc}
{Pat Stanford , pat (at) coviana.com}

Var H1: Handle;

Begin
	H1:=FSymDef;
	While H1<>nil do
		Begin
			SetObjectVariableBoolean(H1,127,True);
			H1:=NextSymDef(H1);
		End;
End;

Run(SetSymbolsToInsertAsGroups);

There is a very good chance that this will not properly traverse Symbol Folders, so if you need that we will have to look more closely.

 

I am assuming the "remarks" is a field in a custom record that you have attached to each symbol definition. If this is so then change the SetObjectVariable line to something like:

 

SetRField(H1, 'Name of my Custom Record', 'remarks', 'This is what I want my remark to be');

 

Ask again if this is not enough help.

 

 

Link to comment

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.

×
×
  • Create New...