Import vs ImportGui: Materials

Need help, or want to share a macro? Post here!
Xel
Posts: 3
Joined: Thu Nov 22, 2018 1:32 pm

Import vs ImportGui: Materials

Postby Xel » Thu Nov 22, 2018 2:27 pm

Hi,

I am trying to import step files on the command line and do something to them (eg. save them as collada file).

The problem is, they always loose the color/material when run on the commandline.

I was trying different things and ended up with some minimal examples:

Code: Select all

import FreeCAD
import Import
import importDAE

doc = FreeCAD.newDocument()
FreeCAD.setActiveDocument(doc.Name)
Import.insert("file.stp", doc.Name)
importDAE.export(doc.Objects, "file.dae")
vs

Code: Select all

import FreeCAD
import ImportGui
import importDAE

doc = FreeCAD.newDocument()
FreeCAD.setActiveDocument(doc.Name)
ImportGui.insert("file.stp", doc.Name)
importDAE.export(doc.Objects, "file.dae")
While the ImportGui Version works perfectly in keeping colors, it is impossible to run it on the commandline.
And the plain Import Version runs perfectly on the commandline, but strips all colors.
I also tried

Code: Select all

import FreeCAD
import Part
import importDAE

doc = FreeCAD.newDocument()
FreeCAD.setActiveDocument(doc.Name)
Part.insert("file.stp", doc.Name)
importDAE.export(doc.Objects, "file.dae")
Part.insert("file.stp", doc.Name)
but that strips off the colors too.

Seems to happen with every file I tried - and so it does with the AS1-TU-203 file from https://www.cax-if.org/library/index.html

All these examples can be used from within FreeCAD or as python scripts run with FreeCAD (the one without Gui can be run with FreeCAD or FreeCADCmd, doesn't matter)

I am running 0.18_pre 14976 on MacOSX AND Ubuntu (mainly because it is the only one I can run collada exports on without errors), but I see the same behavior on 0.17 (besides me being unable to export to collada).

Is there any way to import step files without Gui, while preserving the colors?
User avatar
bernd
Posts: 10976
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Import vs ImportGui: Materials

Postby bernd » Fri Nov 23, 2018 5:20 am

Xel
Posts: 3
Joined: Thu Nov 22, 2018 1:32 pm

Re: Import vs ImportGui: Materials

Postby Xel » Mon Nov 26, 2018 12:57 pm

Well, maybe it is because of that - maybe not.

I solved my problem by using xvfc to run it against a virtual display…
Thats not a great solution, but as far as I can tell the only one…
User avatar
Kunda1
Posts: 8772
Joined: Thu Jan 05, 2017 9:03 pm

Re: Import vs ImportGui: Materials

Postby Kunda1 » Mon Nov 26, 2018 3:38 pm

Xel wrote:
Mon Nov 26, 2018 12:57 pm
I solved my problem by using xvfc to run it against a virtual display…
Thats not a great solution, but as far as I can tell the only one…
What do you mean ? Can you provide more detail ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Xel
Posts: 3
Joined: Thu Nov 22, 2018 1:32 pm

Re: Import vs ImportGui: Materials

Postby Xel » Tue Nov 27, 2018 10:00 am

As it seems currently impossible to keep colors/material intact using FreeCAD in commandline mode, I do not use it in commandline mode.

As it is not possible to run FreeCAD in GUI mode without having some sort of graphical environment (which I obviously do not have on a server) I use xvfb to simulate such an environment and run the gui mode from commandline.

The downside is that this will use more resources, the upside is that I can use freecad to generate screenshots (preview images) for the files this way.
User avatar
bernd
Posts: 10976
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Import vs ImportGui: Materials

Postby bernd » Wed Nov 28, 2018 8:03 am

we should may be fill in a bug on mantis in the regard of colors and commandline?
Christian.Bar
Posts: 1
Joined: Mon Mar 18, 2019 3:12 pm

Re: Import vs ImportGui: Materials

Postby Christian.Bar » Mon Mar 18, 2019 3:24 pm

Hi All,
any news on this???

Thanks!
iamnotstone
Posts: 3
Joined: Fri Jul 05, 2019 2:12 pm
Location: China

Re: Import vs ImportGui: Materials

Postby iamnotstone » Wed Nov 13, 2019 6:56 am

hey! I found the answer. Please check the return value of

Code: Select all

v =  Import.insert('path_to_stp', 'doc_name')
print(v)
If your step file has color information. the return value of the insert function should be an array object. otherwise, it returns None.

you'll found the color data in the list
drakh
Posts: 1
Joined: Tue Feb 25, 2020 9:54 am

Re: Import vs ImportGui: Materials

Postby drakh » Tue Feb 25, 2020 9:57 am

iamnotstone wrote:
Wed Nov 13, 2019 6:56 am
hey! I found the answer. Please check the return value of

Code: Select all

v =  Import.insert('path_to_stp', 'doc_name')
print(v)
If your step file has color information. the return value of the insert function should be an array object. otherwise, it returns None.

you'll found the color data in the list
seems, that this does not work either. i have stp with colors in it and this returs me none :(
User avatar
Kunda1
Posts: 8772
Joined: Thu Jan 05, 2017 9:03 pm

Re: Import vs ImportGui: Materials

Postby Kunda1 » Tue Feb 25, 2020 2:18 pm

drakh wrote:
Tue Feb 25, 2020 9:57 am
seems, that this does not work either. i have stp with colors in it and this returs me none :(
Welcome to the forum, @drakh
Please familiarize yourself with the Forum Guidelines
For example, please add you About info to help requests or comments like this so we can tell if you're using the most up to date version of FC and its dependencies.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features