Material Utilities addon not working due to API changes #93749

Closed
opened 2021-12-06 13:23:59 +01:00 by Oleg · 8 comments

System Information
Operating system: Windows-10-10.0.19043-SP0 64 Bits
Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 461.40

Blender Version
Broken: version: 3.0.0, branch: master, commit date: 2021-12-02 18:35, hash: blender/blender@f1cca30557
Worked: (newest version of Blender that worked as expected)

Short description of error
Materials are not populated

Python: Traceback (most recent call last):
  File "D:\Programs\Blender\stable\blender-3.0.0+stable.f1cca3055776\3.0\scripts\addons\materials_utils\menus.py", line 56, in draw
    icon_value = material.preview.icon_id)
AttributeError: 'NoneType' object has no attribute 'icon_id'

location: <unknown location>:-1

Exact steps for others to reproduce the error

  • Enable Material Utilities addon
  • Press Shift+Q and select "Assign Material" or "Select by Material" - list is emty
**System Information** Operating system: Windows-10-10.0.19043-SP0 64 Bits Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 461.40 **Blender Version** Broken: version: 3.0.0, branch: master, commit date: 2021-12-02 18:35, hash: `blender/blender@f1cca30557` Worked: (newest version of Blender that worked as expected) **Short description of error** Materials are not populated ``` Python: Traceback (most recent call last): File "D:\Programs\Blender\stable\blender-3.0.0+stable.f1cca3055776\3.0\scripts\addons\materials_utils\menus.py", line 56, in draw icon_value = material.preview.icon_id) AttributeError: 'NoneType' object has no attribute 'icon_id' location: <unknown location>:-1 ``` **Exact steps for others to reproduce the error** - Enable Material Utilities addon - Press Shift+Q and select "Assign Material" or "Select by Material" - list is emty
Author

Added subscriber: @DotBow

Added subscriber: @DotBow
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @zion3

Added subscriber: @zion3

Hello, I'm creating an addon and I get a similar error in blender 3.0, as I understand the 'icon_id' is not created immediately when creating the material and that's why it can't find it, what I did is use another icon until the 'icon_id' is created which will be updated later, since I use it in a dynamic list.

I hope it helps.

Just change one line in the code:
(ms : list of materials)

before:

if ms:
        for i in range(len(ms)):
            icon = ms[i].preview.icon_id
            list.append((ms[i].name, ms[i].name, '', icon, i))
    return list

now:

if ms:
        for i in range(len(ms)):
            icon = 'NODE_MATERIAL' if not hasattr(ms[i].preview, 'icon_id') else ms[i].preview.icon_id 
            list.append((ms[i].name, ms[i].name, '', icon, i))
    return list
Hello, I'm creating an addon and I get a similar error in blender 3.0, as I understand the 'icon_id' is not created immediately when creating the material and that's why it can't find it, what I did is use another icon until the 'icon_id' is created which will be updated later, since I use it in a dynamic list. I hope it helps. Just change one line in the code: (ms : list of materials) before: ``` if ms: for i in range(len(ms)): icon = ms[i].preview.icon_id list.append((ms[i].name, ms[i].name, '', icon, i)) return list ``` now: ``` if ms: for i in range(len(ms)): icon = 'NODE_MATERIAL' if not hasattr(ms[i].preview, 'icon_id') else ms[i].preview.icon_id list.append((ms[i].name, ms[i].name, '', icon, i)) return list ```
Author

This comment was removed by @DotBow

*This comment was removed by @DotBow*

Hello, for those interested, I was researching more and the best way to rearrange the code was forcing the creation of the icon_id with: preview_ensure()

now:

if ms:
    for i in range(len(ms)):
         ms[i].preview_ensure()
         icon = ms[i].preview.icon_id
         list.append((ms[i].name, ms[i].name, '', icon, i))
    return list
Hello, for those interested, I was researching more and the best way to rearrange the code was forcing the creation of the icon_id with: preview_ensure() now: ``` if ms: for i in range(len(ms)): ms[i].preview_ensure() icon = ms[i].preview.icon_id list.append((ms[i].name, ms[i].name, '', icon, i)) return list ```

To be clear, to anyone else looking to resolve this issue - this was my workaround. Go to the 'menu.py' file, and around line 57-60, ang change:

        for material_name, material in materials:
            ....

to:

        for material_name, material in materials:
            # Note: added to address
            # https://projects.blender.org/blender/blender-addons/issues/93749
            material.preview_ensure()

And the same around line 124:

                # Note: added to address
                # https://projects.blender.org/blender/blender-addons/issues/93749
                material.preview_ensure()
                
                if material.users > 0:
                    op = layout.operator(bl_id,
                                    text = material_name,
                                    icon_value = material.preview.icon_id
                                    )

Then revert / reload blender - this is just what worked for me).
Hopefully that helps!

To be clear, to anyone else looking to resolve this issue - this was my workaround. Go to the 'menu.py' file, and around line 57-60, ang change: ``` for material_name, material in materials: .... ``` to: ``` for material_name, material in materials: # Note: added to address # https://projects.blender.org/blender/blender-addons/issues/93749 material.preview_ensure() ``` And the same around line 124: ``` # Note: added to address # https://projects.blender.org/blender/blender-addons/issues/93749 material.preview_ensure() if material.users > 0: op = layout.operator(bl_id, text = material_name, icon_value = material.preview.icon_id ) ``` Then revert / reload blender - this is just what worked for me). Hopefully that helps!
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-12-17 14:13:38 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#93749
No description provided.