How to access Body objects from a python script?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Umut
Posts: 6
Joined: Tue Feb 28, 2023 7:23 am

Re: How to access Body objects from a python script?

Post by Umut »

Here is some update:

When I ran my python file externally, newly saved CaseEdit.FCStd file has everything else. For example sketch which I draw to create Pad is there. So file name is read correctly, and something is saved as CaseEdit.FCStd. Even without saveas command, as I said in previous entries, when I open the file and listed objects using external code, sketch or any other items are there, for example I can see facebinders, but no bodies.

Why do I care for bodies, because I want to make changes in parameters to update sketch and then perhaps export updated part. But since sketch and generated parts or surfaces are no longer connected (for example no Pad object), they are not changing eventhough the parameter values are updated.

I also tried the code in another pc in another freecad just now. The outcome is the same.

So what I understand, I'm missing something while importing FreeCAD or something about initializing it, something which is done automatically when you open freecad as gui or freecadcmd int the background.

Regards

Umut
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to access Body objects from a python script?

Post by onekk »

Umut wrote: Tue Mar 21, 2023 11:01 am ...
Yes probably you are trying to achieve something that is related to the way FreeCAD manage things, I'm out of my comfort zone, as there are too much complications on using an external Python as FreeCAD is meant to be an Application, and not a Library.

When used as a library you have no all the Gui part but even the init part, so you are simply import what FreeCAD is exposing as methods, and probably you lose something.

freecadcmd probably is doing the init thing simply you have no Gui part.

But as said it is only a guess supported from some posts I have read about other people trying to importing FreeCAD and use it not as a standalone Application.

Sorry to not be of more help.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply