io_export_dxf: Fix exporting object with empty material slot #104554

Closed
Oxicid wants to merge 2 commits from (deleted):oxicid-dxf-empty-mat into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 5 additions and 13 deletions

View File

@ -3,7 +3,7 @@
bl_info = { bl_info = {
"name": "Export Autocad DXF Format (.dxf)", "name": "Export Autocad DXF Format (.dxf)",
"author": "Remigiusz Fiedler (AKA migius), Vaclav Klecanda", "author": "Remigiusz Fiedler (AKA migius), Vaclav Klecanda",
"version": (2, 2, 3), "version": (2, 2, 4),
"blender": (2, 80, 0), "blender": (2, 80, 0),
"location": "File > Export > AutoCAD DXF", "location": "File > Export > AutoCAD DXF",
"description": "The script exports Blender geometry to DXF format r12 version.", "description": "The script exports Blender geometry to DXF format r12 version.",

View File

@ -93,21 +93,13 @@ def getCommons(ob, settings):
if DEBUG: print('ob_layer_nr=', ob_layer_nr) #-------------- if DEBUG: print('ob_layer_nr=', ob_layer_nr) #--------------
materials = ob.material_slots materials = ob.material_slots
if materials: if materials and materials[0].material:
ob_material = materials[0] ob_material = materials[0]
ob_mat_color = ob_material.material.diffuse_color ob_mat_color = ob_material.material.diffuse_color
else: ob_mat_color, ob_material = None, None else: ob_mat_color, ob_material = None, None
if DEBUG: if DEBUG:
print('ob_mat_color, ob_material=', ob_mat_color, ob_material) #-------------- print('ob_mat_color, ob_material=', ob_mat_color, ob_material) #--------------
data_materials = ob.material_slots
if data_materials:
data_material = data_materials[0]
data_mat_color = data_material.material.diffuse_color
else: data_mat_color, data_material = None, None
if DEBUG:
print('data_mat_color, data_material=', data_mat_color, data_material) #--------------
entitylayer = ENTITYLAYER_DEF entitylayer = ENTITYLAYER_DEF
c = settings['entitylayer_from'] c = settings['entitylayer_from']
#["default_LAYER","obj.name","obj.layer","obj.material","obj.data.name","obj.data.material","..vertexgroup","..group","..map_table"] #["default_LAYER","obj.name","obj.layer","obj.material","obj.data.name","obj.data.material","..vertexgroup","..group","..map_table"]
@ -120,7 +112,7 @@ def getCommons(ob, settings):
elif c=="obj.name": elif c=="obj.name":
entitylayer = ob.name entitylayer = ob.name
elif c=="obj.data.material" and ob_material: elif c=="obj.data.material" and ob_material:
entitylayer = data_material.name entitylayer = ob_material.name
elif c=="obj.data.name": elif c=="obj.data.name":
entitylayer = ob.data.name entitylayer = ob.data.name
@ -138,8 +130,8 @@ def getCommons(ob, settings):
entitycolor = ob.color entitycolor = ob.color
elif cfrom=="obj.material" and ob_mat_color: elif cfrom=="obj.material" and ob_mat_color:
entitycolor = ob_mat_color entitycolor = ob_mat_color
elif cfrom=="obj.data.material" and data_mat_color: elif cfrom=="obj.data.material" and ob_mat_color:
entitycolor = data_mat_color entitycolor = ob_mat_color
entityltype = ENTITYLTYPE_DEF entityltype = ENTITYLTYPE_DEF
etype = settings['entityltype_from'] etype = settings['entityltype_from']