Skip to content

Commit

Permalink
Fix the issue with textures not reloading properly
Browse files Browse the repository at this point in the history
  • Loading branch information
passivestar committed Jan 19, 2024
1 parent fbb2bbe commit b55f1e4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

bl_info = {
'name': 'Substance Import-Export Tools',
'version': (1, 3, 21),
'version': (1, 3, 22),
'author': 'passivestar',
'blender': (4, 0, 0),
'location': '3D View N Panel',
Expand Down Expand Up @@ -238,7 +238,7 @@ def execute(self, context):
for obj in bpy.context.view_layer.active_layer_collection.collection.objects:
if obj.type == 'MESH' and len(obj.data.materials) > 0:
for material in obj.data.materials:
if material is not None and "node_tree" in material:
if material is not None and material.use_nodes:
for node in material.node_tree.nodes:
if node.bl_idname == 'ShaderNodeTexImage':
unique_images.add(node.image)
Expand Down Expand Up @@ -273,6 +273,7 @@ def execute(self, context):
break
# Create an empty mesh object with an empty material slot and set it as active
# This is needed to be able to use the shader editor to assign textures with node wrangler
previous_active_object = context.view_layer.objects.active
temp_mesh = bpy.data.meshes.new(name="TempMesh")
temp_obj = bpy.data.objects.new(name="TempObject", object_data=temp_mesh)
temp_obj.data.materials.append(None)
Expand Down Expand Up @@ -308,6 +309,7 @@ def execute(self, context):
self.report({'ERROR'}, f'Error occurred while adding textures: {e}\n{tb}')
finally:
context.area.type = previous_context
context.view_layer.objects.active = previous_active_object
bpy.data.objects.remove(temp_obj)

return {'FINISHED'}
Expand Down

0 comments on commit b55f1e4

Please sign in to comment.