0
$\begingroup$

I'm trying to import glTF file into Blender and export it as dxf by running a Python script from command line.

I'm able to do this via GUI when I activate both glTF & dxf plugins. I've seen a similar solution for conversion from obj to fbx, which runs fine:

import bpy
bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.obj(filepath="D:\\source.obj")
bpy.ops.export_scene.fbx(filepath="D:\\taget.fbx")

However, glTF and dxf are handled via plugins and I've been unable to modify the code since I'm no Python expert

$\endgroup$
0
$\begingroup$

This is untested, but too much to write in comment.

Would say the gltf addon is default in 2.8 the dxf not. Here is a test script to enable both and set as default and persistent.

If you look at addon info for the two addons in question will note that the folder name in addon folder for each is

"io_export_dxf", "io_scene_gltf2"

this is the key used to enable them using the addon_utils helper method enable, and check if already default and enabled with check

import bpy
from addon_utils import check, enable
bpy.ops.wm.read_factory_settings(use_empty=True)
for addon in ("io_export_dxf", "io_scene_gltf2"):
    default, enabled = check(addon)
    if not enabled:
        enable(addon, default_set=True, persistent=True)

#bpy.ops.import_scene.gltf(filepath="/somepath")    
#bpy.ops.export.dxf(filepath="/somefilepath")

Note commented out the operator calls.

See the output in the python console to find and check what properties can be set for operators.

For example export to dxf. Will reflect those in UI panel when manually exporting.

>>> bpy.ops.export.dxf(
dxf()
bpy.ops.export.dxf(filepath="",
    projectionThrough='NO', 
    onlySelected=True, 
    apply_modifiers=True, 
    mesh_as='3DFACEs', 
    entitylayer_from='obj.data.name', 
    entitycolor_from='default_COLOR', 
    entityltype_from='CONTINUOUS', 
    layerName_from='LAYERNAME_DEF',
    verbose=False)
Export to the Autocad model format (.dxf)

Note properties listed in long winded operator call above are defaults, and only need to be set when non default (eg filepath)

As mentioned untested.

$\endgroup$
  • $\begingroup$ Thanks a lot @batFINGER. Worked like a charm. Sadly, I can't upvote your answer here due to lack of reputation $\endgroup$ – Immugio May 14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.