Macro for new file naming

Programming and macros
Wasermelone
Posts: 7
Joined: Wed Dec 01, 2021 5:54 am
Answers: 0
x 2

Macro for new file naming

Unread post 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.
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 289
x 56

Re: Macro for new file naming

Unread post 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!
Austin
Wasermelone
Posts: 7
Joined: Wed Dec 01, 2021 5:54 am
Answers: 0
x 2

Re: Macro for new file naming

Unread post 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.
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 289
x 56

Re: Macro for new file naming

Unread post 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?
Austin
Post Reply