Sebastiaan Posted June 10 Share Posted June 10 I am trying to convert to group symbols nested in a 3d symbol. Each parent 3D symbol has 4 nested 3d Symbols that I want to convert to group, but each nested 3D symbol may also have nested symbols of their own. I am trying to convert to group the first set of 4 nested symbols whose names al start with '_TransformGroup'. I am using vs.FInSymDef to get to the first nested object. With the below code I can use the for loop to show each of the 4 symbol names in an alert dialog if I omit the vs.SymbolToGroup line. But as soon as I add the vs.SymbolToGroup line the code stops and does not go to the next object as expected. Could anyone point me in the right direction? symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) ) while vs.GetTypeN(symid)==16: symname = vs.GetName(symid) if symname[:20] == 'Lighting Device (3D)': symDef = vs.FInSymDef(vs.GetObject(symname)) for i in range(4): symDefName = vs.GetSymName(symDef) #vs.AlrtDialog(symDefName) if symDefName[:15] == '_TransformGroup': vs.AlrtDialog(symDefName) vs.SymbolToGroup(symDef,0) symDef = vs.NextObj(symDef) else: symDef = vs.NextObj(symDef) symid=vs.NextSymDef(symid) Reduce nested symbols script.vwx Quote Link to comment
MullinRJ Posted June 11 Share Posted June 11 Hello @Sebastiaan, Try getting all of the handles to the symbols you want to convert-to-groups before you convert anything. Then convert them from your stored variables, list, array, whatever. When you convert anything to another object type, you run the risk of changing the stacking order, meaning the next object in the list probably isn't the object that was there before you made the conversion. If your first attempt doesn't work, try converting them in reverse order. If that also doesn't work, write back. Also consider posting an example file. There are ways to navigate object lists while making changes on the fly, but it's probably easier to find all your handles first, then convert the handles one at a time. Raymond Quote Link to comment
Sebastiaan Posted June 11 Author Share Posted June 11 (edited) 7 hours ago, MullinRJ said: Hello @Sebastiaan, Try getting all of the handles to the symbols you want to convert-to-groups before you convert anything. Then convert them from your stored variables, list, array, whatever. When you convert anything to another object type, you run the risk of changing the stacking order, meaning the next object in the list probably isn't the object that was there before you made the conversion. If your first attempt doesn't work, try converting them in reverse order. If that also doesn't work, write back. Also consider posting an example file. There are ways to navigate object lists while making changes on the fly, but it's probably easier to find all your handles first, then convert the handles one at a time. Raymond What you said about the stacking order does make sense, as after the first SymboltoGroup the next object seemed to become the next nested symbol that was in the symbol that I converted to group. I did try the list approach, I made a list of the nested symbols with the getname function, but it seemed to do nothing, as if this does not work when you are withinin a parent symbol? Am alertdialog would name the symbols but the convert to group did nothing. Could you give an example of how to get all handles of the symbol? Do you mean getting all 4 handles of all 4 symbols that I want to convert via a list? Or more handles per symbol? Edit: btw I had added the example file in the opening post 🙂 I did manage to make this part of my quest to work with the following workaround by nesting the convert loop in a another loop, that way I could break the sequence and run it again until all 4 symbols are converted symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) ) while vs.GetTypeN(symid)==16: symname = vs.GetName(symid) if symname[:20] == 'Lighting Device (3D)': for i in range(4): symDef = vs.FInSymDef(vs.GetObject(symname)) for i in range(4): symDefName = vs.GetSymName(symDef) #vs.AlrtDialog(symDefName) if symDefName[:15] == '_TransformGroup': #vs.AlrtDialog(symDefName) vs.SymbolToGroup(symDef,0) symDef = vs.NextObj(symDef) else: symDef = vs.NextObj(symDef) symid=vs.NextSymDef(symid) Edited June 11 by Sebastiaan add extra line Quote Link to comment
Sebastiaan Posted June 11 Author Share Posted June 11 Also would you or anyonknow if there is a function to delete and replace a symbol definition directly in the recourse manager like we can do with right click on the symbol in the resource manager? Can this be done with scripting too? It would be an alternate and maybe even better approach to my end goal of this challenge. @MullinRJ @Pat Stanford? Quote Link to comment
MullinRJ Posted June 11 Share Posted June 11 1 hour ago, Sebastiaan said: Could you give an example of how to get all handles of the symbol? Do you mean getting all 4 handles of all 4 symbols that I want to convert via a list? Or more handles per symbol? Yes, make an empty List in Python and append the 4 handles you want to convert to the List. Next, iterate over that List and convert each one to a Group. 1 hour ago, Sebastiaan said: Edit: btw I had added the example file in the opening post Sorry, I missed that. I'll look at it tomorrow. It's WAY past my bed time. 1 hour ago, Sebastiaan said: would you or anyonknow if there is a function to delete and replace a symbol definition directly in the recourse manager like we can do with right click on the symbol in the resource manager? I'm not sure if this is what you want, but look at SetHDef(). It doesn't work on elements of the RM, but will redefine a placed Symbol with a different SymDef, which sounds like what you are asking. That's All Folks, Raymond Quote Link to comment
Sebastiaan Posted June 11 Author Share Posted June 11 1 hour ago, MullinRJ said: Yes, make an empty List in Python and append the 4 handles you want to convert to the List. Next, iterate over that List and convert each one to a Group. Sorry, I missed that. I'll look at it tomorrow. It's WAY past my bed time. I'm not sure if this is what you want, but look at SetHDef(). It doesn't work on elements of the RM, but will redefine a placed Symbol with a different SymDef, which sounds like what you are asking. That's All Folks, Raymond Thanks @MullinRJ, playing with SetHDef() And got it to work on the first test! with below code. Now to expand the script to finish the challenge thx! vs.SetHDef('_TransformGroup', 'Group') symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) ) while vs.GetTypeN(symid)==16: symname = vs.GetName(symid) if symname[:20] == 'Lighting Device (3D)': #for i in range(4): symDef = vs.FInSymDef(vs.GetObject(symname)) #for i in range(4): symDefName = vs.GetSymName(symDef) #vs.AlrtDialog(symDefName) if symDefName[:15] == '_TransformGroup': #vs.AlrtDialog(symDefName) Symobjnew = vs.GetObject('Group') vs.AlrtDialog(Symobjnew) vs.AlrtDialog(symDef) vs.SetHDef(symDef, Symobjnew) #vs.SymbolToGroup(symDef,0) symDef = vs.NextObj(symDef) else: symDef = vs.NextObj(symDef) symid=vs.NextSymDef(symid) Quote Link to comment
Pat Stanford Posted June 11 Share Posted June 11 To script the symbol replacement you would need to do it manually. There is not way to access the replace all. So pick the symbol you want to replace with, replace all the symbols in the drawing, then delete the original symbol definition. Quote Link to comment
Sebastiaan Posted June 11 Author Share Posted June 11 1 hour ago, Pat Stanford said: To script the symbol replacement you would need to do it manually. There is not way to access the replace all. So pick the symbol you want to replace with, replace all the symbols in the drawing, then delete the original symbol definition. I was thinking of just doing a purge after running the script that should work to clean up the RM shouldn’t it? Quote Link to comment
Pat Stanford Posted June 11 Share Posted June 11 Yes purge should work. But you would have to have the correct settings in the Purge dialog box. And I don't think you can change those settings by script. Quote Link to comment
Sebastiaan Posted June 11 Author Share Posted June 11 1 hour ago, Pat Stanford said: Yes purge should work. But you would have to have the correct settings in the Purge dialog box. And I don't think you can change those settings by script. Ah yes. No problem to do the purge by hand. In this case the script will automate enough work. Thx! 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.