[Solved] Running FreeCAD in headless mode

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jeff3danimation
Posts: 5
Joined: Thu Sep 19, 2019 9:40 pm

[Solved] Running FreeCAD in headless mode

Post by jeff3danimation »

Good evening,

I am currently developing a set of tools for an artist on my team and am using FreeCAD in a headless mode. I've been lurking on the forums (without an account) and found a lot of the work and discussions here to be immensely helpful. Looking at some of the tutorials and scripting advice, I have a few questions that started to pop up...

When running headless mode (using Python to manipulate FreeCAD in a back-end manner), would I be able to use FreeCADGui's classes and functions when FreeCAD is not booted?

How am I able to, programmatically, assign colors to individual faces with version .18?

Is FreeCAD able to select objects based on angle or type of vectorized parameter (I.E. a filleted face versus a chamfered face versus a planar face)?


Pardon, as my knowledge with this robust library is still fairly new to me.

Thank you,
Jeff
Last edited by Kunda1 on Fri Sep 20, 2019 7:31 pm, edited 1 time in total.
Reason: Marked this thread as [Solved]
User avatar
naxq0
Posts: 51
Joined: Wed Apr 25, 2018 7:45 am

Re: Running FreeCAD in headless mode

Post by naxq0 »

Hey there jeff

Haven't played around much with the FreeCADGui classes, but I think for the most part you need to start up the GUI. For instance, the color info is not loaded when you're on headless mode.

That doesn't mean you can't automate it though, you can start up and hide the GUI by doing something like this:

Code: Select all

        import FreeCAD, FreeCADGui
        FreeCADGui.showMainWindow()
        mw = FreeCADGui.getMainWindow()
        mw.hide()
then you can run python commands as if you were in the GUI's own embedded python interpreter (run things like FreeCAD.ActiveDocument.ActiveObject, get colors etc.)

You should also be able to assign colors to faces that way using the GUI importer, which also exports :)

Code: Select all

import ImportGui
As for selecting faces based on angle or vectorized parameter... I'm not sure I know what you mean. Most 3D data formats don't have much in the way of properties you could read, maybe the color in some cases?

So unless there's something you can read like that, you might have to resort to some if/else magic to try to weed out the face you're looking for
jeff3danimation
Posts: 5
Joined: Thu Sep 19, 2019 9:40 pm

Re: Running FreeCAD in headless mode

Post by jeff3danimation »

That sounds like a pretty good plan. I'll give it a try today and see what I can come up with. Optimally, I'd like to have a pipeline set up to delete faces that have attained a red color to the faces.

Thank you, Naxq0!

Also, if you don't mind my inquiry, do you know of a way to set colors based on a selection? There is that hidden gem in the Combo View that allows you to select faces and add a color, but I want to automate that process and can't find any documentation based on this particular feature.
jeff3danimation
Posts: 5
Joined: Thu Sep 19, 2019 9:40 pm

Re: Running FreeCAD in headless mode

Post by jeff3danimation »

Just sending a quick update, you were completely correct regarding running headless mode, Naxq0!

For anyone looking to do the same as me, make sure you launch the main window so that you have access to all of FreeCADGui's classes and methods. You don't actually need to have anything visible or rendered (the main window will not actually show anything beside a blank window with the word "python" in the titlebar) to use its methods.
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: Running FreeCAD in headless mode

Post by Cyril »

Hi jeff,
Have you read this wiki page : Embedding FreeCAD
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
jeff3danimation
Posts: 5
Joined: Thu Sep 19, 2019 9:40 pm

Re: Running FreeCAD in headless mode

Post by jeff3danimation »

I actually did not. Thank you for the source, this would be incredible to work with!
jeff3danimation
Posts: 5
Joined: Thu Sep 19, 2019 9:40 pm

Re: Running FreeCAD in headless mode

Post by jeff3danimation »

I resolved all my issues! Thank you so much for everyone's assistance!

I really appreciate the input regarding what I should look for and do.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Solved] Running FreeCAD in headless mode

Post by Kunda1 »

Documenting headless mode over at Headless FreeCAD
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply