0
$\begingroup$

Could someone provide an example similar to this?

I need an addon located in View3d > Tools.

It has 4 properties on that panel. Each one controls and updates the inptus of the modifier "Geometry Nodes" of the original object "Cube". It has a node tree linked called "GN_Cube". Each addon property should control and update each "GN_Cube" property as follows:

Property_1(float): default value(1.5), it controls the input_2 of the "GN_Cube".

Property_2(float): default value(25), it controls the input_3 of the "GN_Cube".

Property_3(float): default value(2.5), it controls the input_4 of the "GN_Cube".

Property_4(boolean): default value(unchecked), it controls the input_5 of the "GN_Cube".

$\endgroup$
4
  • $\begingroup$ What's "View3d > Tools"? Side panel/Sidebar, Tool tab? Or do you want a menu in the header called Tools? $\endgroup$ Jul 3, 2023 at 13:43
  • $\begingroup$ By the way, you can find correct terminology in the documentation if you are ever unsure. $\endgroup$ Jul 3, 2023 at 13:46
  • $\begingroup$ Sorry, I mean Side panel, like "Item", "View", "Tools", another one like this called for example "Addon controls GN". $\endgroup$
    – Miguel
    Jul 3, 2023 at 13:51
  • $\begingroup$ I mean Sidebar ;) $\endgroup$
    – Miguel
    Jul 3, 2023 at 13:55

1 Answer 1

1
$\begingroup$

I took UI Panel example from Text Editor's Templates -> Python menu and changed it:

import bpy


class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "My Panel"
    bl_category = "Blah Blah"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

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

        scene = context.scene
        # GN Inputs

        o = bpy.data.objects["Cube"] #might not be the best idea to use the name since they change a lot     
        #row.prop(o.modifiers['GeometryNodes'], '["Input_2"]') #testing
        for modifier in o.modifiers:
            if modifier.type != 'NODES': # Skip in case it's not Geometry Nodes modifier
                continue
            for input in modifier.node_group.inputs:
                row = layout.row()
                row.prop(modifier, '["' + input.identifier + '"]', text=input.name) #Because the input for modifier on an object(as opposed to modifier node group) is o.modifiers['GeometryNodes']["Input_2"]
                # Apparently has to be '["..."]', not "['...']"
        
        # Create a simple row.
        layout.label(text=" Simple Row:")

        row = layout.row()
        row.prop(scene, "frame_start")
        row.prop(scene, "frame_end")

        # Create an row where the buttons are aligned to each other.
        layout.label(text=" Aligned Row:")

        row = layout.row(align=True)
        row.prop(scene, "frame_start")
        row.prop(scene, "frame_end")

        # Create two columns, by using a split layout.
        split = layout.split()

        # First column
        col = split.column()
        col.label(text="Column One:")
        col.prop(scene, "frame_end")
        col.prop(scene, "frame_start")

        # Second column, aligned
        col = split.column(align=True)
        col.label(text="Column Two:")
        col.prop(scene, "frame_start")
        col.prop(scene, "frame_end")

        # Big render button
        layout.label(text="Big Button:")
        row = layout.row()
        row.scale_y = 3.0
        row.operator("render.render")

        # Different sizes in a row
        layout.label(text="Different button sizes:")
        row = layout.row(align=True)
        row.operator("render.render")

        sub = row.row()
        sub.scale_x = 2.0
        sub.operator("render.render")

        row.operator("render.render")
        
        


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


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


if __name__ == "__main__":
    register()

It will list all inputs of Geometry Nodes modifiers on bpy.data.objects["Cube"] in the Sidebar, Blah Blah tab

$\endgroup$

You must log in to answer this question.

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