David Poiron Posted August 13, 2021 Share Posted August 13, 2021 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. Quote Link to comment
Pat Stanford Posted August 13, 2021 Share Posted August 13, 2021 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); Quote Link to comment
David Poiron Posted August 13, 2021 Author Share Posted August 13, 2021 Thanks Pat. I seemed to have created a working script similar to your example with "while do" functions, but it appears that foreach object might be more straightforward. I'll try that. Thanks again. Quote Link to comment
Pat Stanford Posted August 13, 2021 Share Posted August 13, 2021 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. Quote Link to comment
Bogdan Ciocan Posted August 19, 2021 Share Posted August 19, 2021 Hi @Pat Stanford, this is a great script and very useful. Thank you for sharing. Can this script be modified or add another procedure, to change not only the value of the Record.Field of all instances but also the value from Resource Manger? Thanks! 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.