Open document without showing in GUI

Need help, or want to share a macro? Post here!
csdehaan
Posts: 4
Joined: Tue Aug 30, 2016 6:17 pm

Open document without showing in GUI

Postby csdehaan » Tue Aug 30, 2016 6:25 pm

I am writing a Python script to generate an assembly. The assembly is made up of numerous parts that are saved in individual FreeCAD files. While creating the assembly I open the part files, copy the part from the file into the assembly document, and then close the part file. This all works OK, but it would look much nicer if I could open a document and copy the part out of it in the background without the document appearing in the GUI. Is this possible?
wmayer
Site Admin
Posts: 14897
Joined: Thu Feb 19, 2009 10:32 am

Re: Open document without showing in GUI

Postby wmayer » Wed Aug 31, 2016 8:11 am

As long as you start the FreeCAD GUI version then it's not possible at the moment. What would be needed is a way to load objects into memory from a project file without creating a document for it.
User avatar
DeepSOIC
Posts: 7074
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Open document without showing in GUI

Postby DeepSOIC » Wed Aug 31, 2016 9:19 am

I want that too, for Lattice ParaSeries. And I need the document be functional, as it copies some objects from active document, change some properties, does recompute, extracts resulting shapes, and closes the temporary document when finished.
ickby
Posts: 2922
Joined: Wed Oct 05, 2011 7:36 am

Re: Open document without showing in GUI

Postby ickby » Wed Aug 31, 2016 9:39 am

Developers Talk: I have some code that would make this possible. Back than my goal was to enhance the GUI mode without Qt Application, to enable the use of FreeCAD Gui part from command line only. I managed to enable use of Gui::Document and ViewProviders etc. from commandline. This worked by having a new InventorView type which has a SceneGraph but no visualisation by QT. Gui::Document and ViewProviders can work with this new view after only very small changes. In the given scenario this new view could be created and used to load the document, it would not be displayed than but could be used fully. However, no idea if there will happen a crash somewhere when the QT window is up and running, I only tested without Qt window. If someone is interested, the code is few months old and not cleaned up, hence never made it to a pullrequest: https://github.com/ickby/FreeCAD_sf_master/tree/guiless
csdehaan
Posts: 4
Joined: Tue Aug 30, 2016 6:17 pm

Re: Open document without showing in GUI

Postby csdehaan » Wed Aug 31, 2016 10:40 pm

wmayer wrote:As long as you start the FreeCAD GUI version then it's not possible at the moment. What would be needed is a way to load objects into memory from a project file without creating a document for it.
Would you say that this is primarily a limitation of the Python API? As in, it would be fairly easy to do, just a matter of exposing the functionality through the API, or is there a more fundamental reason why a window (or tab) needs to be opened whenever a document is opened?
triplus
Posts: 8757
Joined: Mon Dec 12, 2011 4:45 pm

Re: Open document without showing in GUI

Postby triplus » Wed Aug 31, 2016 11:04 pm

csdehaan wrote:
wmayer wrote:As long as you start the FreeCAD GUI version then it's not possible at the moment. What would be needed is a way to load objects into memory from a project file without creating a document for it.
Would you say that this is primarily a limitation of the Python API? As in, it would be fairly easy to do, just a matter of exposing the functionality through the API, or is there a more fundamental reason why a window (or tab) needs to be opened whenever a document is opened?
I feel that @ickby answered you that question. Therefore this isn't limitation of the Python API. It's about removing/replacing Qt related stuff in a way you don't need them anymore to load a document.
csdehaan
Posts: 4
Joined: Tue Aug 30, 2016 6:17 pm

Re: Open document without showing in GUI

Postby csdehaan » Thu Sep 01, 2016 2:04 am

triplus wrote:I feel that @ickby answered you that question. Therefore this isn't limitation of the Python API. It's about removing/replacing Qt related stuff in a way you don't need them anymore to load a document.
Perhaps you are correct, but I did not find that to be obvious from his post. To be clear I am running this in the GUI version of FreeCAD, not the command line version, which is what @ickby had referred to in his post. It seems to me that it should not be necessary to remove/replace QT related stuff for what I want. It would still be fine if the QT window still existed somewhere in the background and long as it was not visible. But then I don't know, which is why I asked.
csdehaan
Posts: 4
Joined: Tue Aug 30, 2016 6:17 pm

Re: Open document without showing in GUI

Postby csdehaan » Thu Sep 01, 2016 2:37 am

OK, I have a better solution. Using mergeProject instead of opening a document and copying the object gives me exactly what I wanted. Thanks.
wmayer
Site Admin
Posts: 14897
Joined: Thu Feb 19, 2009 10:32 am

Re: Open document without showing in GUI

Postby wmayer » Thu Sep 01, 2016 7:36 am

Would you say that this is primarily a limitation of the Python API? As in, it would be fairly easy to do, just a matter of exposing the functionality through the API, or is there a more fundamental reason why a window (or tab) needs to be opened whenever a document is opened?
No, this has nothing to do with Python. It's just the program logic that when the GUI is set-up that signals are sent from App to Gui and the latter reacts on them. What might work too is to allow to create a document directly and not by the application (i.e. FreeCAD.newDocument()). In this case emitting the signals inside the document has in general no effect.
User avatar
brst
Posts: 86
Joined: Thu Apr 18, 2019 10:11 am
Location: Germany

Re: Open document without showing in GUI

Postby brst » Fri Sep 06, 2019 8:23 am

Sorry for gravedigging :)

Did anything change on this matter?

I want to use

Code: Select all

App.ActiveDocument.ActiveObject.Shape.defeaturing
without the document. I didn't find a way to use the defeaturing without the document, so maybe one can open documents without GUI by now.

Greetings brst
FreeCAD rookie