5
$\begingroup$

I'm exposing the input to a Set Material geometry nodes modifier property in my Addon UI through layout.prop(), similar to what was done in this thread. All the inputs work except for the material inputs, which become greyed out and inaccessible in the Addon UI. Why is that? And is there any solution or workaround for this issue?

enter image description here enter image description here

$\endgroup$
5
  • $\begingroup$ aah ok i can reproduce it now. it's really disabled. I previously had a question on how to expose these properties here but this one is weird. $\endgroup$
    – Harry McKenzie
    Commented May 6 at 9:42
  • $\begingroup$ AFAIK some modifier input ID properties can't be modified in a custom layout. It will be grayed out. You also can't set Image textures that way. No idea why $\endgroup$
    – Gorgious
    Commented May 6 at 10:16
  • $\begingroup$ @Gorgious you think I should open a "bug" ticket for this so we can find out from the developers? $\endgroup$
    – Harry McKenzie
    Commented May 6 at 10:32
  • 1
    $\begingroup$ Yes that would be a good idea ! Although I'm sure there is a technical reason this is a bit unfortunate $\endgroup$
    – Gorgious
    Commented May 6 at 11:24
  • 1
    $\begingroup$ @Gorgious oh no more need there is a solution by XY XD $\endgroup$
    – Harry McKenzie
    Commented May 6 at 13:15

1 Answer 1

4
$\begingroup$

Draw Geometry Nodes Modifier Inputs

enter image description here

import bpy

IDNAME_ICONS = {
    "NodeSocketMaterial": "MATERIAL_DATA",
    "NodeSocketCollection": "OUTLINER_COLLECTION",
    "NodeSocketTexture": "TEXTURE_DATA",
    "NodeSocketImage": "IMAGE_DATA",
}
IDNAME_TYPE = {
    "NodeSocketMaterial": "materials",
    "NodeSocketCollection": "collections",
    "NodeSocketTexture": "textures",
    "NodeSocketImage": "images",
}

def draw_gn_prop(layout, md, rna): # Need to ensure that md and identifier are correct
    if rna.bl_socket_idname == "NodeSocketGeometry": return

    if rna.bl_socket_idname in IDNAME_ICONS:
        layout.prop_search(md, f'["{rna.identifier}"]',
            search_data = bpy.data,
            search_property = IDNAME_TYPE[rna.bl_socket_idname],
            icon = IDNAME_ICONS[rna.bl_socket_idname],
            text = rna.name
        )
    else:
        layout.prop(md, f'["{rna.identifier}"]', text=rna.name)


class OBJECT_PT_CustomPanel(bpy.types.Panel):
    bl_label = "Custom Panel"
    bl_idname = "OBJECT_PT_custom_panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        md_name = "GeometryNodes"

        ob = context.object
        if hasattr(ob, "modifiers") and md_name in ob.modifiers:
            md = ob.modifiers[md_name]
            if md.type == "NODES" and md.node_group:
                for rna in md.node_group.interface.items_tree:
                    if hasattr(rna, "in_out") and rna.in_out == "INPUT":
                        draw_gn_prop(layout, md, rna)


def register():
    bpy.utils.register_class(OBJECT_PT_CustomPanel)

def unregister():
    bpy.utils.unregister_class(OBJECT_PT_CustomPanel)

if __name__ == "__main__":
    register()
$\endgroup$
3
  • $\begingroup$ oh interesting there is a prop_search nice thank you so much for sharing! $\endgroup$
    – Harry McKenzie
    Commented May 6 at 13:17
  • $\begingroup$ Ah, that is a nice solution ! And a great use of the poorly documented prop_search. Thank you. $\endgroup$
    – Gorgious
    Commented May 6 at 14:58
  • $\begingroup$ works like a charm!!! $\endgroup$
    – baby boss
    Commented May 6 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .