The Hamma Posted August 29, 2020 Share Posted August 29, 2020 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); Quote Link to comment
JBenghiat Posted August 29, 2020 Share Posted August 29, 2020 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. Quote Link to comment
The Hamma Posted August 30, 2020 Author Share Posted August 30, 2020 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 Quote Link to comment
Pat Stanford Posted August 30, 2020 Share Posted August 30, 2020 Another way around this is to build the entire criteria string as a single variable. They you can use vs.ForEachObject ( ExplodeSymbols , "Your_Criteria_String " ). Quote Link to comment
Recommended Posts
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.