Placing the image selection block on the user panel

In Blender, the block of buttons for selecting an image in the Image Editor is placed in the header of the area by default. If necessary, it can also be placed in the user panel.

We can place an image selection block in the user panel using the template_ID() function of the bpy.types.UILayout object, which is responsible for drawing interface components in Blender.

We need to pass the following parameters to the function:

  • a pointer to the data block of the workspace area – “context.space_data”
  • the name of the property, for images in the Image Editor, it will be “image”
  • additionally, we can pass a pointer to an open a new image function – “image.open”.

We will call this function in the draw function of the custom user panel class.

After registering our class in the Blender Python API

in the Image Editor user panel, we will get a duplicate of the button block for selecting images.

If instead of selecting the current image, we need to define a separate image instance and assign an image to it, for example, to compare with the current one, we can define a separate block of buttons for it using the same template_ID function.

First, let’s define a custom property containing a link to the image:

Now we can access it with:

To make a selection buttons block for it in our user panel, in the parameters of the template_ID function we need to specify a link to the data block – “context.window_manager”, and the property name – “image”.

Defina a call to this function in our custom panel class:

After registering our class in the Blender Python API, the block of buttons for selecting a custom image will be placed in the user panel in the Image Editor area.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments