Jiajing Posted April 26, 2023 Share Posted April 26, 2023 (edited) import vs; List = ['Astera AX5','Astera AX3','ChromaQ ColorForce II 12'] for i in List: vs.AlrtDialog(i) vs.NameClass(i) Running code on VWX 2023, it suppose to create three classes as ' Astera AX5' , 'Astera AX3' , 'ChromaQ ColorForce II 12', but it creates ' Astera AX6' , 'Astera AX4' , 'ChromaQ ColorForce II 13'. Basically, numbers in the end get +1 increment for some reason. I am not sure how to fix that. any leads are appreciated Broken File.vwx Edited April 26, 2023 by Jiajing Quote Link to comment
Jiajing Posted April 26, 2023 Author Share Posted April 26, 2023 (edited) 5 minutes ago, Jiajing said: import vs; List = ['Astera AX5','Astera AX3','ChromaQ ColorForce II 12'] for i in List: vs.AlrtDialog(i) vs.NameClass(i) Running code on VWX 2023, it suppose to create three classes as ' Astera AX5' , 'Astera AX3' , 'ChromaQ ColorForce II 12', but it creates ' Astera AX6' , 'Astera AX4' , 'ChromaQ ColorForce II 13'. Basically, numbers in the end get +1 increment for some reason. I am not sure how to fix that. any leads are appreciated Interestingly, I tried the same code on a brand new file, it works. lol Edited April 26, 2023 by Jiajing Quote Link to comment
twk Posted April 26, 2023 Share Posted April 26, 2023 (edited) If there is an existing class name with a digit at the end of the class name, creating a class with the same name will increment that last digit in the class name Edited April 26, 2023 by twk Quote Link to comment
Jiajing Posted April 26, 2023 Author Share Posted April 26, 2023 Thanks for quick response. Good to know. It would be great to add this note to the NAMECLASS wiki page. On wiki page, it only mentioned 'If the specified class already exists, then it will become the active class of the document.' https://developer.vectorworks.net/index.php/VS:NameClass Thank you Quote Link to comment
JBenghiat Posted April 26, 2023 Share Posted April 26, 2023 Unique names affect more than just the class list. The name list includes resources, classes, and names assigned to objects. For example, if you have a symbol named "Astera AX5," you can't also have a class with the same name. I believe layers is the only object type that doesn't share the name list, but there may be a few others. Generally, any time you create a named object, you should check to see if the name already exists. Checking if vs.Name2Index() > 0 is a good way to confirm the existing name. 2 Quote Link to comment
Jiajing Posted April 26, 2023 Author Share Posted April 26, 2023 7 minutes ago, JBenghiat said: Unique names affect more than just the class list. The name list includes resources, classes, and names assigned to objects. For example, if you have a symbol named "Astera AX5," you can't also have a class with the same name. I believe layers is the only object type that doesn't share the name list, but there may be a few others. Generally, any time you create a named object, you should check to see if the name already exists. Checking if vs.Name2Index() > 0 is a good way to confirm the existing name. Thank you, Josh. That explained, after I delete symbol, the code works just fine. good to know. I can not have class named 'Astera AX5', but I can add prefix and have class named as 'LX-Asteria AX5'. That might be a work around. 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.