API command for "make assembly from part"?

Programming and macros
Kjara
Posts: 21
Joined: Mon Jul 19, 2021 2:49 am
Answers: 0
x 1

API command for "make assembly from part"?

Unread post 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.
User avatar
AlexB
Posts: 448
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

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

Unread post 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
User avatar
AlexLachance
Posts: 2023
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2179
x 1880

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

Unread post 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
Kjara
Posts: 21
Joined: Mon Jul 19, 2021 2:49 am
Answers: 0
x 1

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

Unread post 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.
User avatar
AlexB
Posts: 448
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

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

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