Acess Scenegraph through python API in without Gui mode

Need help, or want to share a macro? Post here!
Maninesan
Posts: 11
Joined: Wed Mar 09, 2016 4:07 am

Acess Scenegraph through python API in without Gui mode

Postby Maninesan » Sun Mar 20, 2016 10:36 am

How can I access scene-graph of whole document scene or particular object via python api in ubuntu console? I try to follow the instructions given in the Pivy page [1] but I can't access/create documents through FreeCADGui in setupWithoutGui Mode!

http://freecadweb.org/wiki/index.php?title=Pivy
wmayer
Site Admin
Posts: 16455
Joined: Thu Feb 19, 2009 10:32 am

Re: Acess Scenegraph through python API in without Gui mode

Postby wmayer » Sun Mar 20, 2016 10:52 am

but I can't access/create documents through FreeCADGui in setupWithoutGui Mode!
No, that's not possible because in this case on Gui side nothing happens. It neither creates a document on the Gui nor sets it up a scene graph.

The best what you can do is using showMainWindow() instead and then access the main window and hide it.
ickby
Posts: 2982
Joined: Wed Oct 05, 2011 7:36 am

Re: Acess Scenegraph through python API in without Gui mode

Postby ickby » Sun Mar 20, 2016 10:56 am

Hello,

when using setupWithoutGui() the GUI event system does not work, as no qt event loop is statet. This means all the "ActiveDocument" and "ActiveObject" attributes are never set, they are useless. You can still access the scene graph, as en example have a looke here: http://www.freecadweb.org/wiki/index.ph ... reeCAD_Gui
The code does not work fully due to pivy problems with the viewer, but gives you an impression how this could work.

The most important function here is

Code: Select all

root=FreeCADGui.subgraphFromObject(obj)
which gives you access to the objects viewprovider root node. From there you need to experiment a bit what is possible and what not in this mode.
ickby
Posts: 2982
Joined: Wed Oct 05, 2011 7:36 am

Re: Acess Scenegraph through python API in without Gui mode

Postby ickby » Sun Mar 20, 2016 11:03 am

also note that wmayer is of course correct that the whole gui document is not setup in this mode. but the function I showed you initializes the sub scenegraph for one object and makes it accessible, what is exactly what we want! have a look at the implementation, it migth help a lot understanding freecad view system:
https://github.com/FreeCAD/FreeCAD/blob ... n.cpp#L261
Maninesan
Posts: 11
Joined: Wed Mar 09, 2016 4:07 am

Re: Acess Scenegraph through python API in without Gui mode

Postby Maninesan » Fri Mar 25, 2016 4:47 am

Hi,
Why Coin3D Scenegraph construction always combined with Qt? I mean Why we can't run SetupWithoutGUI mode without starting a QApplication(sys.argv)?
ickby
Posts: 2982
Joined: Wed Oct 05, 2011 7:36 am

Re: Acess Scenegraph through python API in without Gui mode

Postby ickby » Fri Mar 25, 2016 6:05 am

Maninesan wrote:I mean Why we can't run SetupWithoutGUI mode without starting a QApplication(sys.argv)?
You mean why it crashs when doing it without a QApplication? At least it does for me when testing. This is IMHO a bug which should be fixed. I will look at this over the weekend.

EDIT: it seems this always crashing for me. I need to dig further :) can you explain a bit more in detail what you mean, what works with QApplication and what not?
Maninesan
Posts: 11
Joined: Wed Mar 09, 2016 4:07 am

Re: Acess Scenegraph through python API in without Gui mode

Postby Maninesan » Fri Mar 25, 2016 6:57 am

ickby wrote: can you explain a bit more in detail what you mean, what works with QApplication and what not?
I'm still digging through it :? , I will update the status soon :)
ickby
Posts: 2982
Joined: Wed Oct 05, 2011 7:36 am

Re: Acess Scenegraph through python API in without Gui mode

Postby ickby » Fri Mar 25, 2016 9:07 am

Ah ok found the problem. The application adds default commands, which needs to access the QApplication. If not available it crashs. As a first workaround change src/Gui/Application.cpp, line 436 to this:

Code: Select all

if(GUIenabled)
    createStandardOperations();
This avoids loading the commands and hence needing the QApplication if one initializes without Gui. With this small change it should work for your requirements.

As general note I analyzed the possibilities of setupWithoutGUI() and think it is possible to extend that mode further. But this is out of scope of your project and if your proposal is selected, this is something I would do parallel to your work. As in your proposal the first part of work is to create the scene graph transformation you can do this in normal GUI mode, and for the second half which requires the setupWithoutGUI() mode I will have it extended as I intend to.