Hello Everyone,
Please guide me to how to overcome to this issue.
Just give me some Hint or suggestion i will try to solve this.
ISSUE while using FreeCAD commands in python 3.6 shell
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: ISSUE while using FreeCAD commands in python 3.6 shell
Okay I can confirm this... Indeed the correct viewprovider is not reattributed anymore after opening the file in non-GUI mode, saving it and reopening it with the GUI.
Apparently on file restore, the correct view provider is not set (it's set to 1) I'm pretty sure it was working before, or am i mistaken? Or should we do something manually to set the correct view provider on object restore?
@Werner, can you have a look? I think there is a core issue somewhere here... To reproduce:wmayer wrote: ping
Code: Select all
# run FreeCAD -c
d = FreeCAD.open("slaborignal.FCStd")
d.saveAs("slab2.FCStd")
# run FreeCAD and open slab2
obj = App.getDocument("slab2").getObject("Rectangle")
obj.Proxy
# prints <Draft._Rectangle object at 0x7fb9641a9eb8>
obj.ViewObject.Proxy
# prints 1 - should be Draft_ViewProviderRectangle
Re: ISSUE while using FreeCAD commands in python 3.6 shell
Just look at the GuiDocument.xml file inside an .fcstd file. For the Proxy of custom view providers we write out the module and class name.
In cmd line mode the file GuiDocument.xml won't be created and when opening the project file in GUI mode FreeCAD doesn't know which kind of view providers it should instantiate.
This problem basically only happens for custom Python feature because for C++ features the method getViewProviderName() returns a string of the class that must be instantiated.
If we want to have a true headless FreeCAD (without and workarounds like showing the GUI and hiding it immediately) we have to extend our Python features. Like its C++ counterpart a Python feature should also offer a method getViewProviderName() that returns a tuple of module name and class name (e.g. ("Draft", "_ViewProviderRectangle") or a simple string "Draft._ViewProviderRectangle".
But it should be checked with a proof of concept that this really works.
Code: Select all
<Property name="Proxy" type="App::PropertyPythonObject">
<Python value="bnVsbA==" encoded="yes" module="Draft" class="_ViewProviderRectangle"/>
</Property>
This problem basically only happens for custom Python feature because for C++ features the method getViewProviderName() returns a string of the class that must be instantiated.
If we want to have a true headless FreeCAD (without and workarounds like showing the GUI and hiding it immediately) we have to extend our Python features. Like its C++ counterpart a Python feature should also offer a method getViewProviderName() that returns a tuple of module name and class name (e.g. ("Draft", "_ViewProviderRectangle") or a simple string "Draft._ViewProviderRectangle".
But it should be checked with a proof of concept that this really works.
Re: ISSUE while using FreeCAD commands in python 3.6 shell
Does it mean for C++ features the view provider would not be written in cmd mode either, BUT on reload of the document in Gui mode FreeCAD knows which viewprovider fits to the C++ feature object and takes it with the implemented standard attributes?
The idea is to implement the method for Python Features too.
The idea is to implement the method for Python Features too.
Re: ISSUE while using FreeCAD commands in python 3.6 shell
The class name of the view provider is not written out, but its properties only. Each C++ feature has the virtual method getViewProviderName that returns the class name so that it can be instantiated.Does it mean for C++ features the view provider would not be written in cmd mode either