0
$\begingroup$

I am currently writing my first blender addon and I have opened up one of those sample templates as a reference. I have noticed that if I want to create a button to make it appear I have to use these default string keywords. Eg. frame_start, frame_end or render.render. My question is, can I make my own custom slider or button that doesn't use these predefined string keywords?

At first, I thought these were replaceable strings but if I mistype just one letter the entire button disappears. Basically, I want to create a slider or a button that says "Number of final output images" in the box itself instead of "End Frame:" or "Start Frame: " how should I proceed?

$\endgroup$
1
  • $\begingroup$ Worth mentioning that these "strings" are attribute names. ob.foo is the equivalent of getattr(ob, "foo") andsimilarly with ob.foo = 3 using setattr(ob, "foo", 3). (also the test has_foo = hasattr(ob, "foo") Using the attribute setters and getters is very common (and basic) in python. The UI elements are similar, eg layout.prop(ob, "foo"). $\endgroup$
    – batFINGER
    Jun 1 '18 at 9:00
2
$\begingroup$

The example "strings" that you show belong to two different categories, frame_start and frame_end are property names while render.render is an operator name. The properties will display as a number that you can edit while the operator will show as a button that will perform an action when clicked.

The strings that you use need to match an existing property or operator for them to work, an operator is identified by it's bl_idname property. You can specify a property or operator name and have a different string shown by passing a text paramater.

row.prop(scene, 'frame_start', text='adjust this here')
row.operator('render.render', text='This is my render button')

To create extra properties that are only used by your addon, you can use custom properties, which you should create in your addons register() function.

class MyPanel(bpy.types.Panel):
    ...
    def draw(self, context):
        row = self.layout.row()
        row.prop(context.scene, 'my_prop')

def register():
    bpy.types.Scene.my_prop = bpy.props.IntProperty()
    bpy.utils.register_class(MyPanel)

For operators, you can make your own and then use the bl_idname that you set in your operator class to show a button for it. If no text paramater is passed, an operators bl_label property is shown on the button.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.