Jump to content

vs.ForEachObject vs ForEachObject and the winner is ForEachObject


Recommended Posts

When using vectorscript I can use the following line with itemname being a variable. 

 

ForEachObject ( ExplodeSymbols , ( (INSYMBOL & INOBJECT & INVIEWPORT & (T=SYMBOL) & (S=itemname) ) ) );

 

But when using python i can use the itemname as a variable because the criteria is required to be inserted in quotes. 

vs.ForEachObject ( ExplodeSymbols , "( ( INSYMBOL & INOBJECT & INVIEWPORT & (T=SYMBOL) & (S=itemname) ) ) "  );

 

Does anyone know if there is a way around this.  I tried to replace everything inside the qoutes with a vs.concat created string but it kept asking for a right parenthesis.  Tried to add extra parenthesis to no avail. 

def setrecord(h):
	vs.SetRecord(h, 'ITEM')  # add record to inserted object
	vs.SetRField(h, 'ITEM', 'ITEM', itemname)  # modify record to inserted object


# Modifications to any objects happen here
h = vs.FSymDef()
while h != []:
	global itemname
	itemname = vs.GetName(h)
	vs.SetRecord(h, 'ITEM')  # add record to inserted object
	vs.SetRField(h, 'ITEM', 'ITEM', itemname)  # modify record to inserted object
	grabsymbol = vs.Concat('setrecord',',"S=',itemname,'"')
	vs.ForEachObject(grabsymbol)
	h = vs.NextObj(h)

I did rewrite the script in vectorscript as follows and it worked so I am just asking for future reference. 

 

PROCEDURE ItemRecordfromsymbolname;
VAR
   itemname:string;
   h,H1:handle;

PROCEDURE ExplodeSymbols(h :HANDLE);
BEGIN
	AlrtDialog('running');
	SetRecord(h, 'ITEM');
	SetRField(h, 'ITEM', 'ITEM', itemname);
END;


Begin
H1:=FSymDef;
While H1 <> Nil do
 Begin
       	itemname := GetName(H1);
		SetRecord(H1, 'ITEM');
		SetRField(H1, 'ITEM', 'ITEM', itemname);
		ForEachObject(ExplodeSymbols,((INSYMBOL & INOBJECT & INVIEWPORT & (T=SYMBOL) & (S=itemname))));
   H1:=NextObj(H1);
 End;
End;

Run(ItemRecordfromsymbolname);

 

Link to comment

You want any variables to be surrounded by single quotes in the criteria string. This is actually best practice for vs as well. Python makes this a bit easier, as you can mix quotation types and concatenate strings with "+"

 

e.g. — "(L='" + layerName + "')"

 

Note, to the right of the =, that's a ' and a ". No need to escape the single quote.

Link to comment

Worked perfectly.  I am still learning Python but I find it much simpler than vectorscript. Thank you.

 

"""
This script assigns Item record to symbols in resource manager and instances in drawing. 
It uses the name of the symbol for the value of the Item record. 

It was useful when using a data tag to tag equipment in an equipment plan and elevations. 
I was able to assign the same record to groups in the elevations and use the same data 
tag to mark the items in the elevation.  

This Python Script may be freely distributed. No warranty provided.
Use at your own risk.

David Hamer, 2020-08-30
"""

def setrecord(h):
	vs.SetRecord(h, 'ITEM')  # add record to symbols in drawing
	vs.SetRField(h, 'ITEM', 'ITEM', itemname)  # modify record of the symbol in drawing

h = vs.FSymDef()
while h != []:
	global itemname
	itemname = vs.GetName(h)
	vs.SetRecord(h, 'ITEM')  # add record to symbols in root folder of resource manager
	vs.SetRField(h, 'ITEM', 'ITEM', itemname)  # modify record of symbol in root folder of resource manager
	vs.ForEachObject(setrecord, "(S='"+itemname +"')") #selects symbols of same name in drawing and runs setrecord
	h = vs.NextObj(h) #Looks for next symbol in resouce manager

 

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...