Import vs ImportGui: Materials

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Xel
Posts: 3
Joined: Thu Nov 22, 2018 1:32 pm

Import vs ImportGui: Materials

Post by Xel »

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

Re: Import vs ImportGui: Materials

Post by bernd »

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

Re: Import vs ImportGui: Materials

Post by Xel »

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

Re: Import vs ImportGui: Materials

Post by Kunda1 »

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 ?
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
Xel
Posts: 3
Joined: Thu Nov 22, 2018 1:32 pm

Re: Import vs ImportGui: Materials

Post by Xel »

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

Re: Import vs ImportGui: Materials

Post by bernd »

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

Post by Christian.Bar »

Hi All,
any news on this???

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

Re: Import vs ImportGui: Materials

Post by iamnotstone »

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

Post by drakh »

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

Re: Import vs ImportGui: Materials

Post by Kunda1 »

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.
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