Page 1 of 1

Macro for new file naming

Posted: Wed Dec 01, 2021 6:00 am
by Wasermelone
Hello everyone,

I have a macros that automatically names every new part or assembly created. For example- I choose template that names part- 100,101 etc. and other template names assembly- XX-1, XX-2 etc. However when making new part in assembly everything works fine, macros names part as it should, but when creating subassembly from components macros doesn't work. Is there anyway I can make macros recognize subassembly as an assembly? Or maybe there is some other way around this?

Thanks.

Re: Macro for new file naming

Posted: Thu Dec 02, 2021 10:46 am
by Austin Schukar
Don't know if there's a quicker way, but you can get the component's ModelDoc, IComponent2::GetModelDoc2, then determine the document type via the IModelDoc2::GetType Method. Someone please correct me if I'm wrong, as I've not done this before!

Re: Macro for new file naming

Posted: Fri Dec 10, 2021 1:25 am
by Wasermelone
Thank you for responding! Can you tell me more about this? I'm really new into macros and don't know a lot of things.

Thank you.

Re: Macro for new file naming

Posted: Thu Dec 16, 2021 4:57 pm
by Austin Schukar
Wasermelone wrote: Fri Dec 10, 2021 1:25 am Thank you for responding! Can you tell me more about this? I'm really new into macros and don't know a lot of things.

Thank you.
Sure thing...I can't really go into too much detail, as most of my macros are at the part level, so forgive me for that. From what I understand, SolidWorks API considers parts AND subassemblies as "components" within an assembly. So, you need to get each of the assembly's components, and determine if that component is a part or assembly (subassembly). My guess is to use the methods that I listed above. Make sense?