How to make obj with ViewProvider from outside FreeCAD

Need help, or want to share a macro? Post here!
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

How to make obj with ViewProvider from outside FreeCAD

Postby bernd » Sun Nov 03, 2019 6:19 pm

How do I create objects with ViewProviders from outside FreeCAD?

Code: Select all

import FreeCAD
import Part
import Arch

fname = "archobj"
doc = FreeCAD.newDocument(fname)
Arch.makeComponent(Part.makeBox(300,200,2500))
doc.saveAs("/tmp/" + fname + ".FCStd")
creates an obj with VP if run inside FreeCAD but does not if run in Python outside FreeCAD.

cheers bernd
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to make obj with ViewProvider from outside FreeCAD

Postby bernd » Fri Nov 15, 2019 12:52 pm

noone here who needs view provider outside FreeCAD?
User avatar
furti
Posts: 329
Joined: Mon Nov 27, 2017 5:27 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Postby furti » Fri Nov 15, 2019 3:45 pm

Until now I didn't have a usecase for this.

But the problem might be, that Arch.makeComponent checks if a GUI is initialized.

Code: Select all

...
if FreeCAD.GuiUp:
    ArchComponent.ViewProviderComponent(obj.ViewObject)
...
Without the GUI stuff and coin3D initialized, creating a ViewProvider will not work I think. So my guess it, you have to initialize the FreeCAD Gui before creating the component.
But I don't know if this is possible to do from outside of FreeCAD.
vocx
Posts: 1915
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Postby vocx » Fri Nov 15, 2019 4:47 pm

bernd wrote:
Sun Nov 03, 2019 6:19 pm
...
creates an obj with VP if run inside FreeCAD but does not if run in Python outside FreeCAD.
...
Sorry, Bernd, but I still don't understand your question. What the hell does it mean creating a viewprovider outside of FreeCAD? A view provider is part of FreeCAD, how can you create one without it?
User avatar
furti
Posts: 329
Joined: Mon Nov 27, 2017 5:27 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Postby furti » Fri Nov 15, 2019 5:47 pm

I think what he means is to execute the snippet in his first post in a external python interpreter and save a document including the view provider.

But the viewprovider is not created because there is no FrreCADGui available.
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to make obj with ViewProvider from outside FreeCAD

Postby bernd » Sun Nov 17, 2019 7:40 am

furti wrote:
Fri Nov 15, 2019 5:47 pm
I think what he means is to execute the snippet in his first post in a external python interpreter and save a document including the view provider.

But the viewprovider is not created because there is no FrreCADGui available.
exactly. This is just an example. I would like to create a whole building in a script in a python interpreter outside FreeCAD.

use case: I have set up a python based BIM model server and would like to export the data into FreeCAD document format.
User avatar
Kunda1
Posts: 5946
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Postby Kunda1 » Sun Nov 17, 2019 4:17 pm

This is a good feature to have for sure. Not sure about the technicality of implementing it.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features