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
Assembly 4 Python scripting
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Assembly 4 Python scripting
I don't know
did you try:But I can't figure out how to perform the same operation from my script.Code: Select all
Gui.runCommand('Asm4_makeAssembly',0)
Code: Select all
grep Asm4_makeAssembly *
Re: Assembly 4 Python scripting
It is defined in newAssemblyCmd.py:
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
Code: Select all
Gui.addCommand( 'Asm4_makeAssembly', makeAssembly() )
Thanks,
Marcin
Re: Assembly 4 Python scripting
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.
-
- Posts: 11
- Joined: Thu Aug 18, 2022 5:36 am
Re: Assembly 4 Python scripting
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:
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)