recovering viewprovider after working in no-gui-mode

Need help, or want to share a macro? Post here!
looo
Posts: 1711
Joined: Mon Nov 11, 2013 5:29 pm

recovering viewprovider after working in no-gui-mode

Postby looo » Wed Apr 18, 2018 2:08 pm

Ssomehow the python proxy of the viewprovider gets lost after working in no-gui-mode (jupyter-notebook). While it makes sense that no view-provider is stored in no-gui-mode, my object won't work without the proxy of the viewprovider.

the 2 attachments show the problem.

1. create line in draft and save as fc_with_gui.fcstd
2. start fc in no-gui mode:

Code: Select all

import FreeCAD
doc = FreeCAD.openDocument("fc_with_gui.fcstd")
doc.save("fc_without_gui.fcstd")
3. open the file in freecad (with gui)
Attachments
fc_without_gui.fcstd
(2.11 KiB) Downloaded 4 times
fc_with_gui.fcstd
(3.76 KiB) Downloaded 5 times
User avatar
microelly2
Posts: 3545
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: recovering viewprovider after working in no-gui-mode

Postby microelly2 » Wed May 02, 2018 10:39 am

Does it make sense to recreate the viewprovider after "the document is restored"?

onDocumentRestored(self, obj):
ViewProvider(obj.ViewObject)
looo
Posts: 1711
Joined: Mon Nov 11, 2013 5:29 pm

Re: recovering viewprovider after working in no-gui-mode

Postby looo » Wed May 02, 2018 4:07 pm

microelly2 wrote:Does it make sense to recreate the viewprovider after "the document is restored"?

onDocumentRestored(self, obj):
ViewProvider(obj.ViewObject)
I am not sure if it is the right way. I guess this fnction is also called in nogui-mode.
User avatar
microelly2
Posts: 3545
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: recovering viewprovider after working in no-gui-mode

Postby microelly2 » Wed May 02, 2018 8:29 pm

looo wrote:
Wed May 02, 2018 4:07 pm
[I am not sure if it is the right way. I guess this fnction is also called in nogui-mode.
but you can check whether the gui is up at that moment
looo
Posts: 1711
Joined: Mon Nov 11, 2013 5:29 pm

Re: recovering viewprovider after working in no-gui-mode

Postby looo » Wed May 02, 2018 10:39 pm

yes thats a good idea.