How to make obj with ViewProvider from outside FreeCAD

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

How to make obj with ViewProvider from outside FreeCAD

Post by bernd »

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
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: How to make obj with ViewProvider from outside FreeCAD

Post by bernd »

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

Re: How to make obj with ViewProvider from outside FreeCAD

Post by furti »

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
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Post by vocx »

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?
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
furti
Posts: 344
Joined: Mon Nov 27, 2017 5:27 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Post by furti »

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
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: How to make obj with ViewProvider from outside FreeCAD

Post by bernd »

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
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to make obj with ViewProvider from outside FreeCAD

Post by Kunda1 »

This is a good feature to have for sure. Not sure about the technicality of implementing it.
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
Post Reply