MarcelP102 Posted July 20, 2021 Share Posted July 20, 2021 (edited) As already discused here: https://forum.vectorworks.net/index.php?/topic/61717-make-symbols-unique/ it would be really usefull if there was a button/script that would duplicate a 2D/3D symbol and replace the selected symbol with the new duplicated 'unique' symbol. - Can be a button in PIO, next to the 'replace' button - And/or could be a item in the right-click menu, under the 'replace' option Nice to have: - pop-up that asks the name for the new symbol, by default add -1, -2 etc to the original name - pop-up asking if you want all sub symbols to be unique Starting point: See https://forum.vectorworks.net/index.php?/topic/12522-duplicate-symbol-definition/&tab=comments#comment-396710 And https://gist.github.com/justinmilo/bbc1d64f28509737b601#file-makeunique-py Unfortuantly this script can not duplicate 2D/3D hybrid symbols. But now it's 7 years later. Any possibility that VW script capability has grown so a true "make unique" script is possible? I hope someone can help with this request. This would be super usefull during design studies where we often try out different options. Edited July 20, 2021 by MarcelP102 Quote Link to comment
Popular Post Jesse Cogswell Posted July 20, 2021 Popular Post Share Posted July 20, 2021 (edited) @MarcelP102 I had a little time off this afternoon, so I made you this tool. It will grab all of the data from the latest selected symbol, and essentially duplicate it in the same Resource Manager folder and with the same insertion options. It will then delete the source selected symbol and insert the new one in its place, applying the class and scaling data from the original. The only thing that you will lose is any attached record data. It will prompt you to enter a new name for the symbol, and will autofill with the syntax <Original Symbol Name>'-#', with the number automatically incrementing to the next available number. It's even smart enough to parse the source symbol's name to determine if the last token is a number, then to start incrementing based on that. For example, if you run the command on a symbol named "Symbol-A-1", the script will suggest "Symbol-A-2" as the new name. It will also work on purely 2D symbols, purely 3D symbols, or hybrid symbols. To install it, follow the steps below: Download attached .zip file to a convenient location Start Vectorworks, if it isn't open already Go to Tools - Plug-ins - Plug-in Manager Click on the Third-party Plug-ins tab Click on the Install button Point Vectorworks to the .zip file you downloaded earlier Restart Vectorworks Go to Tools - Workspaces - Edit Current Workspace Click on the Menus tab In the box on the left, scroll down and expand the category named JNC In the box on the right, find a home for the command to live, such as Modify or Tools Click and drag the command Make Symbol Unique from the box on the left to a destination on the right. Click OK Likewise, you can put the command into the menu Object Context so that it is available with right-clicking an object, or assign a shortcut key to it. The script is also smart enough to detect whether the selected object is a symbol, and will tell you if the most recent selected object is not a symbol. MAJOR NOTE: the symbol must be on the currently active layer, as it uses the FSObject command to find the symbol. If you have your Layer Options set to Show/Snap/Modify and select a symbol on a different layer, the tool will yell at you for not selecting a symbol. Let me know if you have any questions or if the tool behaves unexpectedly. Make Symbol Unique.zip Edited July 29, 2021 by Jesse Cogswell Updated plug-in. Added functionality for mirrored symbols, layer elevations, and running on multiple instances of the same symbol at once. 5 1 Quote Link to comment
MarcelP102 Posted July 21, 2021 Author Share Posted July 21, 2021 Amazing! Thank you so much! Quote Link to comment
MarcelP102 Posted July 21, 2021 Author Share Posted July 21, 2021 (edited) @Jesse Cogswell I Have tried the script. It works perfectly for 2D symbols. But when I make a hybrid symbol containing walls unique I get this message see step 2. It's Dutch, but translates into 'Are you sure you want to degroup a object from a higher level?' The view is in 3D and showed the symbol 3x instead of 2x. When clicking YES: Results in a unique hybrid symbol but the walls are copied as polygone lines When clicking NO: Results in correct unique hybrid symbol, without the extra polygone lines. But it has copied the walls outside the symbol 1- Start, 2x orignal symbol 2- Pop-up 3 - Result of selecting YES 4 - Result of selecting NO Edited July 21, 2021 by MarcelP102 Quote Link to comment
Jesse Cogswell Posted July 21, 2021 Share Posted July 21, 2021 @MarcelP102 The way the script works is that creates a new symbol with the unique name, drops the original symbol into the symbol definition, converts the symbol to a group, then ungroups the group to leave in the geometry. For hybrid symbols, it does this twice, once for 2d geometry and once for 3d geometry. My guess is that the error is a result of the walls essentially being dropped in twice, as they are hybrid objects themselves. I'll look into this a bit more tomorrow, I might be able to fix it. Until then, avoid using the tool on symbols containing hybrid plug-in objects (other hybrid symbols should be okay). 1 Quote Link to comment
MarcelP102 Posted July 21, 2021 Author Share Posted July 21, 2021 Great, thanks for taking a look. Quote Link to comment
Jesse Cogswell Posted July 21, 2021 Share Posted July 21, 2021 (edited) @MarcelP102 Took another crack at the script, and I think I got it to work. Let me know if you see anything else that isn't working as expected. You should be able to do the same process using the Install button in the Plug-in Manager to install it as long as you haven't moved it around in your user folder (if so, delete the file from the user folder before installing). No need to worry about editing your workspace again. Make Symbol Unique.zip Edited July 29, 2021 by Jesse Cogswell Updated plug-in. Added functionality for mirrored symbols, layer elevations, and running on multiple instances of the same symbol at once. Quote Link to comment
Pat Stanford Posted July 21, 2021 Share Posted July 21, 2021 If you are not going to worry about records, wouldn't it be easier to just find the resource (by script) and duplicate it and then do the replacement? Would that not keep both the 2D and 3D portions of the symbol intact? 1 Quote Link to comment
Jesse Cogswell Posted July 22, 2021 Share Posted July 22, 2021 (edited) Okay, so I started writing up a whole thing how none of the duplicate commands in the function reference apply to symbol definitions, as those were the things I tried first. But in the process of writing that up, I got an idea to "crawl' through the selected symbol and use CreateDuplicateObject with each object in the symbol. After some tricky coding to get those duplicated objects into the new symbol definition in the proper planes, I was able to make that work and without having to navigate around the quirks with the SymbolToGroup command and the problems it causes with high level objects. The added benefit is that text objects linked to a record format now retain that link, meaning I was able to transfer records over as well, which was a huge downside to the original tool. Big props to @Pat Stanford for making me get off my butt and work for it. Updated tool attached. Same installation as before. EDIT: Due to a request from another user, I've added the option to either retain the original symbol's records in the new symbol, or to overwrite the defaults with the symbol's current values. It will prompt for each attached record, so you don't have to overwrite all of the record formats unless you want to. Make Symbol Unique.zip Edited July 29, 2021 by Jesse Cogswell Updated plug-in. Added functionality for mirrored symbols, layer elevations, and running on multiple instances of the same symbol at once. 2 Quote Link to comment
Pat Stanford Posted July 22, 2021 Share Posted July 22, 2021 CreateDuplicateObject should work for duplicating a symbol. The following is basically from my old archives of the Vectorscript Mail List (sadly defunct) from 2009. Thanks to @Julian Carr @Gerard Jonker and Bill Wood for this information. Procedure DupeSymbol; VAR h1 : HANDLE; s1 : STRING; BEGIN s1 := GetSymName(FSActLayer); h1 := GetObject(s1); IF (h1 <> Nil) & (GetType(h1) = 16) THEN BEGIN h1 := CreateDuplicateObject(h1, GetParent(h1)); SetName(h1, Concat(s1, '-1')); END; END; Run(DupeSymbol); 2 Quote Link to comment
Jesse Cogswell Posted July 22, 2021 Share Posted July 22, 2021 After further testing, CreateDuplicateObject DOES INDEED work for duplicating symbol definitions, just not in Vectorworks 2019 where I was developing the original script. I made a quick test file with the code Pat posted above, and it would not work in 2019 at all. Opened the exact same file in 2021 and it worked just fine in duplicating symbol definitions. I'm going to keep the original code as is to maintain backwards compatibility. Quote Link to comment
MarcelP102 Posted December 24, 2021 Author Share Posted December 24, 2021 Hi @Jesse Cogswell we are now in the progress of modeling an existing highly modular building. You plugin is a real timesaver! Thanks again! A college noticed a hybrid 2d/3d within a symbol cannot be made unique when in 3D edit mode. Making the symbol unique in 2D edit mode works correctly. But sometimes it's more difficult to select the object in 2D mode. Being able to make the symbol unique in 3D mode would be great. Can your take a look, perhaps it's a small fix? See screenshot and file below. Best wishes for 2022! Error plugin.vwx Quote Link to comment
Jesse Cogswell Posted December 24, 2021 Share Posted December 24, 2021 @MarcelP102 It took me a bit to figure out what was causing the bug, but it was really easy to fix once I found it. The script works by building a "blank" symbol definition using a locus point, then copying all of the components from the original symbol into the new symbol definition, then finally deleting the locus point. It breaks when the script is run inside a symbol, as the locus point is created in the 2D component of the symbol, so the new symbol definition doesn't actually get created. The fixed script will now pull your current view projection and create a 2D locus if in Top/Plan view or a 3D locus if you're in a 3D view. I did some tests and couldn't make it break, so you should be good to go. Happy holidays! Make Symbol Unique.zip 2 Quote Link to comment
MarcelP102 Posted January 10, 2022 Author Share Posted January 10, 2022 Hi Jesse, can confirm it is working as expected. Thanks! Ps. Would it be an idea to start an github/gitlab account where you collect your plugins? That would make the discovering of your plugins better and gives us the possibility to share translated versions of you plugins. You can then simply link to the plugin instead of uploading it to all the different forum topics. Quote Link to comment
MarcelP102 Posted July 29, 2022 Author Share Posted July 29, 2022 Hi @Jesse Cogswell I found two bugs while working with 3D symbols. 1. When making the bars unique some bars gets duplicated. Sometimes even multiple times. See screenshots and attached file. Before After 2. When making this symbol unique the mirrored symbols gets flipped. See screenshots and attached file. Before /after Make unique - duplicates.vwx Make unique - mirrored objects.vwx Quote Link to comment
The Hamma Posted April 2 Share Posted April 2 @Jesse Cogswell, I just found this script and it is awesome. Just wanted to make everyone aware that besides the issues as noted by @MarcelP102 above the script also does not work well when the user origin is not the internal origin. The symbol will displace and the symbol's internal origin will also be offset. Jesse if you figure out how to fix the origin issue please let me know as I have a drawing label aigning script that also has the same issue. Quote Link to comment
Jesse Cogswell Posted April 2 Share Posted April 2 (edited) Hmm, I'll need a little more time to investigate the issues that @MarcelP102 mentioned above (I must have been busy when he made the post all those years ago, I don't remember seeing those bugs), but I was able to fix the issue with the internal origin. To compensate for the internal origin, you need to use GetOriginInDocUnits to pull the current User Origin, then subtract those values from the placement or movement script. I had actually done that in the origin version of this script, but rather than applying those values directly to the Symbol call, I instead applied them to the Move3DObj call that moved the newly placed "unique" symbol to match the height of the original object. This works great for objects on Design Layers, but doesn't seem to work with objects on Sheet Layers. I moved added the user origin adjustment to the Symbol call and it seems to work properly. I'll give @MarcelP102's issue a look. I suspect the flip problems arise from having flipped symbols nested inside the symbol you are trying to make unique. The script does do a flip check, but only on the original base symbol instance, not on any nested symbols. Make Symbol Unique.vsm Edited April 2 by Jesse Cogswell 1 1 Quote Link to comment
Jesse Cogswell Posted April 2 Share Posted April 2 After some further testing, this doesn't appear to work with flipped instances of symbols on a Sheet Layer, but works correctly on a Design Layer. I'm currently chalking this up to some oddness with the Mirror function, which may be fixed with the newer MirrorN function added to VW2023. Further testing required. 2 Quote Link to comment
MarcelP102 Posted April 5 Author Share Posted April 5 Great to hear from you again. Looking forward to the mirror fix. Let me know if I can help with any testing. 1 Quote Link to comment
Anthony Esau Posted June 25 Share Posted June 25 (edited) Thanks for your script @Jesse Cogswell! I've been using it for a while and it's been very helpful. Occasionally I would encounter issues with mirrored/flipped objects similar to @MarcelP102, so I took a stab at writing my own version of the "make unique" command in Python (with some assistance from ChatGPT). This script has not been tested extensively so it may have errors or misbehave in some scenarios. It's more simplistic than @Jesse Cogswell's and might not have all the features, but for my use case it works and has been functioning well so far. import vs import re def FSWaldo(): """ Return a handle to the first selected object in the present context of the drawing window. """ # Drop a breadcrumb, a Locus vs.Locus(0, 0) # Get the handle to the Locus locus_handle = vs.LNewObj() # Move it to the bottom of the stacking order, but stay within the current container vs.HMoveBackward(locus_handle, True) # Get the handle to the next selected object above the locus, or None if there are none next_selected_handle = vs.NextSObj(locus_handle) # Discard the Locus vs.DelObject(locus_handle) # Return the handle to the next selected object return next_selected_handle def get_incremented_name(name): match = re.match(r"^(.*?)(-(\d+))?$", name) base_name = match.group(1) number = int(match.group(3)) + 1 if match.group(3) else 1 return f"{base_name}-{number}" obj = FSWaldo() if obj is not None and vs.GetTypeN(obj) == 15: #symbol instance sym_name = vs.GetSymName(obj) sym_def = vs.GetObject(sym_name) new_name = get_incremented_name(sym_name) # Test if an object with the incremented name already exists max_iterations = 1000 # Set a reasonable limit iterations = 0 while vs.GetObject(new_name) != 0 and iterations < max_iterations: new_name = get_incremented_name(new_name) iterations += 1 if iterations >= max_iterations: raise Exception("Maximum iterations reached, possible infinite loop.") new_name = vs.StrDialog("New symbol name", new_name) while vs.GetObject(new_name) != 0: new_name = vs.StrDialog("Name already used. Provide a unique symbol name.", new_name) if new_name != "": # Duplicate the symbol definition new_sym_def = vs.CreateDuplicateObjN(sym_def, vs.GetParent(sym_def), True) # Name the new symbol definition vs.SetName(new_sym_def, new_name) # Set the definition of the symbol instance to the new symbol definition vs.SetHDef(obj, new_sym_def) Edit: And I should say thanks to @Pat Stanford for the snippet about the CreateDuplicateObject command which got me started. Edited June 25 by Anthony Esau Quote Link to comment
MarcelP102 Posted July 12 Author Share Posted July 12 Hi @Anthony Esau your version of the tool works well for me. Only downside is that it doesn't make multiple instances unique. Lets say I have selected two instances of 'symbol-1' and run your script only the first one becomes 'symbol-2'. Is there an option to fix this? Quote Link to comment
Jesse Cogswell Posted July 12 Share Posted July 12 @Anthony Esau Thank you for exposing me to the SetHDef function. It actually solves most of my issues with flipped instances since it negates the need to place a new symbol instance and match the attributes from the original one. I'll get my script updated either this afternoon or early tomorrow. One very exciting thing that I noticed is that it works on Worksheet objects. After a little testing, you can use it to replace the Worksheet that a Worksheet Container object is referencing, which is a feature that's been on the Vectorworks wishlist since forever. I whipped up a quick Replace Worksheet script that will replace the referenced Worksheet for all currently selected Worksheet Containers. Replace Worksheet.vsm 4 Quote Link to comment
Anthony Esau Posted July 15 Share Posted July 15 @MarcelP102 A file with a revised script to handle multiple selected symbols is attached. Try it out. I made a few other minor improvements as well such as clearer variable and function names. @Jesse Cogswell SetHDef was new to me for this occasion as well. It's pretty handy! Make Unique updated to handle multiple selected symbols.vwx 1 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.