Assembly 4 Python scripting

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
meimarcin
Posts: 3
Joined: Wed Mar 27, 2019 6:07 am

Assembly 4 Python scripting

Post by meimarcin »

Hi,

How do I use Assembly 4 workbench from a Python script with FreeCADCmd.exe?

In FreeCAD GUI when I create a new assembly container the Python console shows this:
Gui.runCommand('Asm4_makeAssembly',0)
But I can't figure out how to perform the same operation from my script.
What do I need to import to use Assembly 4 workbench?

Thanks a lot,
Marcin
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 Python scripting

Post by Zolko »

meimarcin wrote: Thu Nov 18, 2021 9:19 pm How do I use Assembly 4 workbench from a Python script with FreeCADCmd.exe?
I don't know

Code: Select all

Gui.runCommand('Asm4_makeAssembly',0)
But I can't figure out how to perform the same operation from my script.
did you try:

Code: Select all

grep Asm4_makeAssembly *
to see where it is defined ?
try the Assembly4 workbench for FreCAD — tutorials here and here
meimarcin
Posts: 3
Joined: Wed Mar 27, 2019 6:07 am

Re: Assembly 4 Python scripting

Post by meimarcin »

It is defined in newAssemblyCmd.py:

Code: Select all

Gui.addCommand( 'Asm4_makeAssembly', makeAssembly() )
I think that the main question is what needs to be imported in a Python scrip to enable access to Assembly 4 Workbench.

Thanks,
Marcin
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 Python scripting

Post by Zolko »

meimarcin wrote: Fri Nov 19, 2021 5:28 pm I think that the main question is what needs to be imported in a Python scrip to enable access to Assembly 4 Workbench.
Everything in the Asm4 workbench is initialized in the InitGui.py file. Every Asm4 file imports FreeCadGui, and many commands use QtWidgets. I don't know how it is for other workbenches, but Asm4 is meant to be used with the Gui. Whether it is possible to use it from the command-line or not, and what needs to be done for that, I don't know.
try the Assembly4 workbench for FreCAD — tutorials here and here
mjbarrow85
Posts: 11
Joined: Thu Aug 18, 2022 5:36 am

Re: Assembly 4 Python scripting

Post by mjbarrow85 »

I was wondering about this too...

I will assume what you want to do is, add something like a Assembly4 part or another Assembly4 model into a master model. If my assumption is wrong, just ignore this. Otherwise you could skip the GUI and use the App::Link class directly:

Code: Select all

#we will add one Assembly4 model 'ModelB' as a sub-model in another Assembly4 model 'ModelA'

model_A = App.ActiveDocument.getObject('ModelA')
L = model_A.Document.addObject("App::Link","ModelB_Link")
model_A.addObject(L)
D = App.openDocument('path_to_ModelB.FCStd')
model_B = D.getObject('ModelB')
L.setLink(model_B)
Post Reply