ViewProvider for (python) objects created in headless mode?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
ViewProvider for (python) objects created in headless mode?
There are a few guys brave enough to use Path headless and create their g-code via a script - however, they are not brave enough to not wanting to double check the result (smart guys)
In other words they want to load the generated file into FreeCAD (with GUI) and look at it. Which doesn't work because Path doesn't assign the ViewObject.Proxy in headless mode. Mostly because it would require loading things like "PySide.QtGui" and other libraries which don't exist in headless mode. So what we end up with are FeaturePython objects without their UI properly being setup.
So the question is - how should this be done correctly?
How does the view provider get attached to an object when the object was created in an environment where no view providers existed?
In other words they want to load the generated file into FreeCAD (with GUI) and look at it. Which doesn't work because Path doesn't assign the ViewObject.Proxy in headless mode. Mostly because it would require loading things like "PySide.QtGui" and other libraries which don't exist in headless mode. So what we end up with are FeaturePython objects without their UI properly being setup.
So the question is - how should this be done correctly?
How does the view provider get attached to an object when the object was created in an environment where no view providers existed?
Re: ViewProvider for (python) objects created in headless mode?
anybody got some insight on how to deal with this issue?
Re: ViewProvider for (python) objects created in headless mode?
I remember I was exploring headless FC stuff in the recent past.but I can't find the posts atm. @Vocx had some good insight in to this. One of the issues that you run into immediately is that the codebase is oriented to the GUI not being activated. His idea was to start adding the condition:
I'm on my mobile right now so I'll need to come back to this
Code: Select all
If GUI.isUp
else
headless_stuff_here
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
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
Re: ViewProvider for (python) objects created in headless mode?
It's not possible to create or access the view provider in headless mode.So the question is - how should this be done correctly?
How does the view provider get attached to an object when the object was created in an environment where no view providers existed?
Here is the code how to access the view provider of an object in GUI mode:
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L190
What's possible is to load FreeCADGui in headless mode but there is no way to access the GUI document because it won't be created and consequently there exist no view providers.
However, what's possible (and this is what kunda probably meant) is to create a scene graph representation of an object. This works this way:
Code: Select all
import FreeCADGui as Gui
from pivy import coin
Gui.setupWithoutGUI()
doc = App.newDocument()
obj = doc.addObject("Part::Box","Box")
doc.recompute()
view = Gui.subgraphFromObject(obj)
Re: ViewProvider for (python) objects created in headless mode?
Started a wiki page to document this 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
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
- sliptonic
- Veteran
- Posts: 3459
- Joined: Tue Oct 25, 2011 10:46 pm
- Location: Columbia, Missouri
- Contact:
Re: ViewProvider for (python) objects created in headless mode?
The desire is to create documents in headless mode that, when opened in the GUI later, will look and behave as though they were created in the GUI originally.
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: ViewProvider for (python) objects created in headless mode?
I also needed this for my csv2freecad script. The actual situation is that the generated objects (vertices) are hidden when I open the file in "normal" FreeCAD and I cannot change the values related to the view, for example the point size.
Interestingly, the vertex objects have a Visibility class member (available in my script), which, as I said, has no influence.
Interestingly, the vertex objects have a Visibility class member (available in my script), which, as I said, has no influence.
Re: ViewProvider for (python) objects created in headless mode?
How about to work on separating things at least to have the ability to load a FreeCAD window that have very little "burden" of the Gui Part.
To be more clear.
Some visualization commands, to rotate ad change view, a TreeView maybe collapsible or detachable and a big visualisation windows like in Gimp.
Or maybe a hide buttons with a relative scriptable commands that will hide most of the Gui and leave only the TreeView, maybea "detachable" Python Console and Report Window.
In this manner, when scripting, you could have the Visualization part, that is relevant and with a button click regain the ability to use the Gui if needed.
Maybe not the best solution, but could be a good improvement some efforts have been done by one user I think, with TreeView ans console that are autohiding when not in use (Modern UI if i don't remember wrong).
Regards
Carlo D.
To be more clear.
Some visualization commands, to rotate ad change view, a TreeView maybe collapsible or detachable and a big visualisation windows like in Gimp.
Or maybe a hide buttons with a relative scriptable commands that will hide most of the Gui and leave only the TreeView, maybea "detachable" Python Console and Report Window.
In this manner, when scripting, you could have the Visualization part, that is relevant and with a button click regain the ability to use the Gui if needed.
Maybe not the best solution, but could be a good improvement some efforts have been done by one user I think, with TreeView ans console that are autohiding when not in use (Modern UI if i don't remember wrong).
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: ViewProvider for (python) objects created in headless mode?
This is something I would like to be able to do as well. In BIM processing this is needed quite often.
Re: ViewProvider for (python) objects created in headless mode?
The reason why the objects are hidden is that a project created in headless mode lacks of a GuiDocument.xml.galou_breizh wrote: ↑Fri Feb 26, 2021 3:40 pm I also needed this for my csv2freecad script. The actual situation is that the generated objects (vertices) are hidden when I open the file in "normal" FreeCAD and I cannot change the values related to the view, for example the point size.
Interestingly, the vertex objects have a Visibility class member (available in my script), which, as I said, has no influence.
When reading in a project then the objects are made invisible to avoid expensive renderings of the scene graph that can considerably slow-down the loading.
Now with a normal project file the GuiDocument.xml is read-in as almost last file and this then changes the visibility again but if the file is lacking all objects stay invisible.