Jump to content
Developer Wiki and Function Reference Links ×

Replace record format information in symbol instances


Recommended Posts

I would like to create a script that replaces the content of an attached record format field in symbol instances that match the currently selected symbol instance. My thought is that this could work in one of two ways:

 

1. replace the record format field contents in other instances, or

2. replace the symbol instances entirely with the currently selected symbol instance, all of which are based on the same symbol definition.

 

Does anyone know of a similar script out there? I have used VS many years ago and am very rusty, but a similar script might get me to the goal faster.

Link to comment

Hi @David Poiron Try the script below and see if it works for you. You set the record and field in the Const block at the top. The script then checks to see if the first selected object is a symbol. If it is, it then reads the symbol name and the value of the Record.Field specified and stores that same value into every other instance of that symbol in the drawing.

 

Ask again if you need more help.

 

Procedure UpdateFieldsToMatchSelected;

{August 13, 2021}
{©2021 Patrick Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}

{No Warranty Expressed of Implied. Use at your own risk.}

{If you need to transfer more than one field, add additional}
{variables, GetRField lines in the main program, and SetRField}
{lines in Execute.}
{Change the Constants to match your record and field names}

CONST	MyRecord='Record 1';	{'MyRecordName';}
		MyField='Field 1';		{'MyFieldName';}
		
VAR
	S1,S2,SymName	:String;
	H1				:Handle;
	
	{Execute is the procedure called by ForEachObject}
	Procedure Execute(Hd1:Handle);
	BEGIN
		SetRField(Hd1,MyRecord,MyField,S1);  {For each object set the variable to the value of S1 from main program}
	End;
	
{This is the beginning of the main program}
BEGIN
	H1:=FSActLayer;
	If GetTypeN(H1)=15 Then {Only run if the selected object is a Symbol}
		BEGIN
			SymName:=GetSymName(H1);
			S1:=GetRField(H1,MyRecord,MyField); {store the field value in variable S1}
			{The CHR(39) in the next line insert a single quote mark. You can get the equivalent}
			{of this using double or triple single quote marks, but that makes my eyes hurt.}
			{It is really hard to miss the CHR(39) statement even if it takes up more room.}
			S2:=Concat('((S=',CHR(39),SymName,CHR(39),'))');  {Make the entire Criteria into a single string variable S2}
	{AlrtDialog(Concat(S2)); (* uncomment this line for debugging exactly what criteria you are using*)}
			ForEachObject(Execute, S2);  {Use the criteria to specify which objects get passed to Execute}{((S='Symbol-1'))}
		End;
End;

Run(UpdateFieldsToMatchSelected);

 

Link to comment

If you can specify the correct Criteria, ForEachObject is usually the cleanest solution in VW. It eliminates your having  to manually handle Handles and worry about when you are done. 😉

 

ForEachObjectInLayer and ForEachObjectInList can also be useful. They take a Function that returns a Boolean for success for Execute (or whatever name you want to use) rather than a procedure.

 

I used to use DoIt (Do it) as my callback procedure name. Until someone jokingly said they thought it was DOLT and I was insulting them for not knowing how to do it. I hate Sans Serif fonts.

 

Let me know if you need more 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...