Scott Stanelle Posted February 11, 2022 Share Posted February 11, 2022 (edited) Hi, I have a python script the uses the vs.SetHDef() procedure to replace a referenced symbol's definition with a new definition. This works perfectly. All the symbols using the old symbol definition are now referencing the new symbol definition. The only minor annoyance is that if I attempt to delete the old, unused, symbol definition from the resources folder, Vectorworks still thinks the symbol definition is referenced and asks me if I want to delete the symbol definition completely. Since I know for sure that it is not referenced, I go ahead and delete it. But I was wondering if there is some other python script procedure that I need to call to perhaps clean up old defunct references to the old symbol definition? Interestingly, if I manually replace the symbol without invoking the script, I do not get the dialog prompt asking if I want to delete completely. Thanks, Scott Edited February 11, 2022 by Scott Stanelle Quote Link to comment
Pat Stanford Posted February 11, 2022 Share Posted February 11, 2022 There are a lot of things that don't actually occur in the drawing until the script actually finishes running. Some of these you can work around and some you can't. I would try some combination of ReDraw, ReDrawAll, and ResetObject to see if one of them will convince VW that the symbol has actually stopped being used before the script ends and the drawing regenerates. HTH Quote Link to comment
JBenghiat Posted February 11, 2022 Share Posted February 11, 2022 You might be mixing some nomenclature here. A “referenced” symbol means that the definition is referenced in from another file. This is in contrast to the distinction between a symbol instance and a symbol definition. Does the error say the symbol is in use or that it is referenced? 1 Quote Link to comment
sstanelle Posted February 12, 2022 Share Posted February 12, 2022 Hi @JBenghiat, Sorry about the confusion with nomenclature. Both the symbol instance and the symbol definition exist in the same file. And I'm not getting an error, just an annoying popup that indicates the symbol is in use and do I really want to delete it completely. In this case, it is safe for me to delete it since I know it's not being used any where else in the file. Just wondering why the popup in the first place. Regards, Scott Quote Link to comment
JBenghiat Posted February 12, 2022 Share Posted February 12, 2022 I see that the documentation for SetHDef muddles the terminology a bit. How are you traversing the objects to be replaced? Are they all symbol instances in the drawing? If you have symbols inside other symbols, or plug-in objects that store an instance of the symbol to avoid a purge, or the symbol in something like a viewport annotation, you might be missing some of the instances. If you test your script on a new file that only contains a few symbol instances of the type you want to replace, you should see that you can delete the symbol without warning. You can also replace one symbol with another when deleting it. Is your script performing extra functions that prohibit you from just replacing symbols on deletion? 1 Quote Link to comment
Scott Stanelle Posted June 3, 2022 Author Share Posted June 3, 2022 Hi JBenghiat, After a long hiatus, I am finally getting back to this. To answer your question of how I am traversing objects, I have a symbol definition consisting of symbols from a resource folder. So rather than replacing a symbol in my drawing, I am actually trying to replace a symbol in a symbol definition. For my current purposes, I am ignoring the actual replacement of the symbol and reduced the task to simply removing the symbol of a given name from anywhere that it occurs in the symbol definition. Once this is done, I attempt to delete the symbol from my resources folder and receive the message that it is still referenced (even though I don't believe it is). I am attaching my code to hopefully make clearer my traversal method. My symbol definition can contain both symbols and groups of symbols. The reason I wrote this script in the first place is because the team I'm writing the script for doesn't want to necessarily replace a symbol in every symbol definition that references it. So I allow them to select the symbol definitions where they wish to replace the symbol. It is in the fringe case where they do replace the symbol in all the symbol definitions that reference it where they encounter the warning message. Obviously in this case, they could use the built in VW Delete/Replace function, but it seems they want to access this function from a single place. I'm ready to tell them to just live with it! 🙂 Best, Scott Delete Symbol.txt Quote Link to comment
JBenghiat Posted June 3, 2022 Share Posted June 3, 2022 Without digging too much into this, you may need to call a reset on the outer symbol. Quote Link to comment
Scott Stanelle Posted June 4, 2022 Author Share Posted June 4, 2022 Hi JBenghiat, Thanks for the quick response. I have tried calling the vs.ResetObject() on the symbol definition before without any success. I tried again just now to confirm. Maybe if you have a few minutes next week, you could take a look at my test script. I'm curious if I am even traversing the object correctly or if there might be a better way to do the traversal. Thanks for any help, Scott 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.