Page 1 of 1

API command for "make assembly from part"?

Posted: Thu Oct 06, 2022 7:48 am
by Kjara
Is there an API method for this user action?
grafik.png

I know I can create a new assembly via ISldWorks.NewDocument(...) and then add a new component via IAssemblyDoc.AddComponent5(...).
But since IAssemblyDoc.AddComponent5(...) does not work if the IAssemblyDoc is invisible, which is a requirement for me, I am looking for alternatives in hope of finding something that works without the user noticing anything.

Re: API command for "make assembly from part"?

Posted: Thu Oct 06, 2022 8:59 am
by AlexB
You can use the RunCommand with the argument swCommands_MakeAssemblyFromPartAssembly

https://help.solidworks.com/2017/englis ... mmand.html

https://help.solidworks.com/2017/englis ... nds_e.html

Edit:
Further research shows this may be a more friendly API option
https://help.solidworks.com/2017/Englis ... nents.html

Re: API command for "make assembly from part"?

Posted: Thu Oct 06, 2022 9:37 am
by AlexLachance
I know your question is API related, but there are more instances I'm sure you could incorporate into your macro.

https://help.solidworks.com/2019/englis ... sembly.htm

Re: API command for "make assembly from part"?

Posted: Fri Oct 07, 2022 7:24 am
by Kjara
RunCommand with swCommands_MakeAssemblyFromPartAssembly is, according to the API docs, what is internally called when clicking "make assembly from part". Since it opens the "Begin Assembly" PropertyManager page, this does not go without the user noticing. Too bad!

-> Or is there a way to programmatically choose the necessary stuff in that PropertyManager page and hide the page from the user altogether?

IAssemblyDoc.MakeAssemblyFromSelectedComponents is a nice idea as well but unfortunately not usable in my case, as I only have a singe document (a part or assembly) open and want to make an assembly from that opened document (i.e. create a new assembly with one component for that document). So there is no assembly from which I can select components to use for MakeAssemblyFromSelectedComponents.

Re: API command for "make assembly from part"?

Posted: Fri Oct 07, 2022 8:40 am
by AlexB
Kjara wrote: Fri Oct 07, 2022 7:24 am RunCommand with swCommands_MakeAssemblyFromPartAssembly is, according to the API docs, what is internally called when clicking "make assembly from part". Since it opens the "Begin Assembly" PropertyManager page, this does not go without the user noticing. Too bad!

-> Or is there a way to programmatically choose the necessary stuff in that PropertyManager page and hide the page from the user altogether?

IAssemblyDoc.MakeAssemblyFromSelectedComponents is a nice idea as well but unfortunately not usable in my case, as I only have a singe document (a part or assembly) open and want to make an assembly from that opened document (i.e. create a new assembly with one component for that document). So there is no assembly from which I can select components to use for MakeAssemblyFromSelectedComponents.
I'll have to look into that. I didn't realize it wouldn't add a single part file with that method. In the past, when creating an assembly I manually added each part to a new assembly document with the API. Slightly cumbersome, but it worked pretty well. Getting things mated with API was more frustrating though...