Buttons, panels, and menus. In this chapter of Scripting for Artists, Sybren shows the basics of creating your own user interface in Blender.
Hi sybren, thanks for your tutorial! I just get confused at around 9:00, about the "Big Grid" and "Small Grid". The Sample's code is like:
props = self.layout.operator('mesh.monkey_grid',
text='Big Grid',
icon='MONKEY')
props.count_x = 10
props.count_y = 10
props.dize = 0.8
props = self.layout.operator('mesh.monkey_grid',
text='Small Grid',
icon='MONKEY')
props.count_x = 1
props.count_y = 1
But how can a single variable props
work for two buttons? The fact is when I'm running this script on Blender 4.1, the Small Grid button didn't show up. So is there anything I've missed? Hope for explain.
Sorry, I just found that I made mistake, typing props.size
to props.dize
. And script quit silently from that line. After correcting it, the small button showed up. But I'm still can't understand my origin question, why a single props
can work for two buttons. Maybe there's no single words can explain why, still hope for explaination.
Thanks for the tutorial. But how do I make the x, y and size values be defined by user input in the panel? I tried:
def draw(self, context): #draw panel
col = self.layout.column(align=True)
props = col.operator('mesh.monkey_grid',
text = 'Generate Grid',
icon = 'MONKEY')
col.label(text="Column Two:")
col.prop(props, 'count_x')
col.prop(props, 'count_y')
col.prop(props, 'size')
The fields with the default paramaters show up in the panel, but I'm not able to change them. My guess is that I have to work with variables. I tried a couple of things, but I failed. Anyone?
*@Tijm Lanjouw* You have to define the user-editable properties somewhere else. If they are to be saved within the blend file, you typically would add them to bpy.types.Scene
. If they are temporary, you typically add them to bpy.types.WindowManager
. You can then use them to assign for example props.count_x = context.scene.my_monkey_grid_count_x
.
You cannot use operator properties with layout.prop()
.
@Sybren A. Stüvel For those searching, this is explained better in chapter 11 ;)
A very clear and resourceful video. Even after making 30+ addons I learned a few things. e.g: I will certainly use columns starting now ;), thanks Doc.
Join to leave a comment.