Hello,
I want to create a UI element that lets me change the Inputs of a GeometryNode setup.
Despite only minor coding experience, I got along okay so far.
The GeometryNode inputs are not really that user friendly as of right now. I.E. Bools are a 0/1 Slider rather than your typical checkbox.
So since I am already putting everything in that UI panel I thought: “hey, let’s change that”…
When I add the bool directly from the geoNodes though it also displays it incorrectly (still a slider).
I managed to get an empty boolean to display the way I like - but I don’t know how I would make it influence the modifier.
A major problem to me is, that I couldn’t find satisfying documentation about “self.layout.row.prop()”.
Take i.E. “row.prop(geom_modifier, ‘[“Input_11”]’, text=“bool”)” from the code below:
text=“bool” - self explanatory
but why wouldn’t it say geom_modifier[“Input_7”] instead of splitting it into two with a comma? Because that’s how I’d change the value outside of this mysterious prop() command.
When I use prop() to call something from bpy.ops I just have to type in the one command into the parenthesis. With a variable from the modifier it becomes two.
And the row.prop(context.scene.custom_props, ‘bool_toggle’) makes even less sense to me.
‘bool_toggle’ is the name I gave it - alright. But where does […].custom_props come from? Is it an arbitrary name? Why am I getting the bool from context and not from the CustomPropertyGroup class?
Well - but If you can’t answer these questions it’s alright. I mainly need to know how to ‘convert’ my boolean into a checkbox.
What’s the best tactic here?
here is the code. I marked the important part with “##############”
import bpy
###Variables###
Geo = bpy.data.objects['KBHR_Blank'] #my object with the modifier
geom_modifier = Geo.modifiers["geometrynodes"] #The Geonodes Modifier
class CustomPropertyGroup(bpy.types.PropertyGroup): #the class with the checkbox-type bool i draw
bool_toggle: bpy.props.BoolProperty(name='bool toggle')
class MODS_PT_GEO (bpy.types.Panel):
bl_label = "GeoNode Controller"
bl_idname = "MODS_PT_GEO"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
my_tool = context.scene
######################################################################
row = layout.row()
row.prop(geom_modifier, '["Input_7"]', text="height") #some int slider
row.prop(geom_modifier, '["Input_11"]', text="bool") #the bool that is displayed as a slider
row = layout.row()
row.prop(context.scene.custom_props, 'bool_toggle') #the correct looking Bool I try to connect to geonodes
######################################################################
###registering and unregistering###
def register():
bpy.utils.register_class(CustomPropertyGroup)
bpy.types.Scene.custom_props = bpy.props.PointerProperty(type=CustomPropertyGroup)
bpy.utils.register_class(MODS_PT_GEO)
def unregister():
del bpy.types.Scene.custom_props
bpy.utils.unregister_class(CustomPropertyGroup)
bpy.utils.unregister_class(MODS_PT_GEO)
if __name__ == '__main__':
register()
Here’s the File: https://drive.google.com/file/d/19VaXpiEFh_uXNEwusXV1v6Z_KmGayE5g/view?usp=sharing