Hi!
I am trying to export one 3D object as .gltf using FreeCAD 0.20.
If I do it with the GUI it is saved fine, but how canI do it with a Python script?
Thanks!
Export Part as gltf
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Export Part as gltf
Hi and welcome to the forum!
Did you try the code from the Python console?
Did you try the code from the Python console?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Export Part as gltf
I recorded a Macro while I was doing it manually with the GUI, the resulting code used ImportGUI, which is not available in my Python code.
Maybe I should also clarify that the script I am running is executed in Ubuntu Console with FreeCAD imported as a library; not in FreeCAD Console.
In the past, for exporting in STEP format, I replaced ImportGUI.export by Import.export in my code and worked, but if I run it does not produce any file
Maybe I should also clarify that the script I am running is executed in Ubuntu Console with FreeCAD imported as a library; not in FreeCAD Console.
In the past, for exporting in STEP format, I replaced ImportGUI.export by Import.export in my code and worked, but if I run
Code: Select all
Import.export(__my_objs__, "file.gltf")
Re: Export Part as gltf
Hello
Speaking about code, probably posting a complete example would be better, as copying and pasting a single line of code is not telling as example what __myobjs__ is, and this could be crucial to solve you problem.
And even the full FreeCAD version info as suggested in: https://forum.freecadweb.org/viewtopic.php?f=3&t=2264
As example I export a part as a STEP file with:
Code: Select all
f_name = "proper_file_name_with_extension"
obj = rear_wheel() # Here the object is created as a TopoShape
obj_do = Part.show(obj, "rear_wheel") # And then converted as a "DocumentObject" to be passed to the export Part
Part.export([obj_do], f_name)
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Export Part as gltf
Thanks for the example!
I am using the following daily version:
And I created a little example reporducing my problem, just paste in a python file and run it with the python interpreter:
That code should produce a STEP and an GLTF file, but only ea.step is produced, while no error is thrown.
Bets regards,
Alfonso
I am using the following daily version:
Code: Select all
OS: Ubuntu 20.04.2 LTS
Word size of FreeCAD: 64-bit
Version: 0.21.
Build type: Release
Branch: unknown
Hash: 45d7151dfa89e974e20fbcfae096b65ed406da23
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.2
Locale: C/Default (C)
Code: Select all
import sys
sys.path.append("/usr/lib/freecad-daily/lib")
import FreeCAD # noqa: E402
import Import # noqa: E402
FreeCAD.newDocument("ea")
document = FreeCAD.getDocument("ea")
cube = document.addObject("Part::Box", "cube")
cube.Length = 1
cube.Width = 1
cube.Height = 1
document.recompute()
Import.export([cube], "ea.step")
Import.export([cube], "ea.gltf")
Bets regards,
Alfonso
Re: Export Part as gltf
Hi,AlfVII wrote: ↑Mon Nov 21, 2022 5:16 pm Thanks for the example!
I am using the following daily version:And I created a little example reporducing my problem, just paste in a python file and run it with the python interpreter:Code: Select all
OS: Ubuntu 20.04.2 LTS Word size of FreeCAD: 64-bit Version: 0.21. Build type: Release Branch: unknown Hash: 45d7151dfa89e974e20fbcfae096b65ed406da23 Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.2 Locale: C/Default (C)
That code should produce a STEP and an GLTF file, but only ea.step is produced, while no error is thrown.Code: Select all
import sys sys.path.append("/usr/lib/freecad-daily/lib") import FreeCAD # noqa: E402 import Import # noqa: E402 FreeCAD.newDocument("ea") document = FreeCAD.getDocument("ea") cube = document.addObject("Part::Box", "cube") cube.Length = 1 cube.Width = 1 cube.Height = 1 document.recompute() Import.export([cube], "ea.step") Import.export([cube], "ea.gltf")
Bets regards,
Alfonso
Same problem here with Import.export .
ImportGui exports the GLTF file, but it requires to import FreeCADGui first.
Even after changing this line:
https://github.com/FreeCAD/FreeCAD/blob ... Gui.py#L36
to:
Code: Select all
FreeCAD.addExportType("glTF (*.gltf *.glb)","Import")
But it think i found the problem:
https://github.com/FreeCAD/FreeCAD/blob ... y.cpp#L383
https://github.com/FreeCAD/FreeCAD/blob ... y.cpp#L721
AppImportGuiPy.cpp has imported and used RWGltf_CafWriter but AppImportPy.cpp doesn't do that.
I can create a pull request but I'm not 100% sure that it will fix the problem.
Thank you FreeCAD community!