41 votes
Accepted

How to call a confirmation dialog box?

When calling an operator via bpy.ops.* without any execution context the execute() method of the respective operator runs by ...
p2or's user avatar
  • 15.5k
33 votes

Duplicating a mesh object

The operator bpy.ops.object.duplicate() will duplicate the selected objects and then make the new duplicate objects selected while de-selecting the original objects....
sambler's user avatar
  • 55.1k
16 votes
Accepted

How do I get the correct context for Python operators?

After looking through the api documentation, it does not appear that there is a direct way to know which contexts an operator will work in. Therefore, one way to determine this is to call an operator'...
David's user avatar
  • 48.9k
14 votes
Accepted

Add menu entry to generic right-click menu?

As of this commit, thanks to @p2or and @brecht, the bpy.ops.ui.copy_data_path_button() operator now allows to copy the full data-path of the active property under the mouse cursor to the clipboard ...
brockmann's user avatar
  • 12.3k
11 votes
Accepted

Create keyboard shortcut for an operator using python?

Minimal add-on example using keymap_items.new() to register a new hotkey CtrlW in 3d View: ...
brockmann's user avatar
  • 12.3k
10 votes
Accepted

How can I catch reports from Operators in Python script?

For Operator Error Reports Catching Errors is handled separately, this example catches the error report and prints it as a string. ...
ideasman42's user avatar
10 votes

How to create toggle button use python in blender

Create a bool property for Window Manager (it can be for anything, but WM will store our modal operator handler so why not put this in the same place): ...
Jaroslav Jerryno Novotny's user avatar
10 votes
Accepted

What does "wm" stand for?

Window manager. As the name suggests Window manager data-block defining open windows and other user interface data The one instance of the window manager ...
batFINGER's user avatar
  • 83.5k
9 votes
Accepted

How to have different origin for each object when separating a mesh by loose parts?

When you switch back to Object Mode, you can set the 'Origin to Geometry'. With all the objects still selected, int the 3D view port, Go to : 'Object' -> 'Transform' -> 'Origin to Geometry' Then ...
dval's user avatar
  • 1,098
9 votes
Accepted

Force a Blender operator to always start with default values

Add 'SKIP_SAVE' to the blender property option set. When defining properties for the operator, any with 'SKIP_SAVE' in their ...
batFINGER's user avatar
  • 83.5k
9 votes
Accepted

How can I add items in the node editor context menu in 2.8?

The Shader Editor context menu is called NODE_MT_context_menu (found by inspecting Preferences> Keymap> Node Editor and looking for Right Mouse) and we can '...
Ray Mairlot's user avatar
9 votes

A comprehensive list of operator overrides

Similarly to the method I used in this answer, one can derive operator overrides from the way they are coded internally (wether in C or in Python). It's time consuming and sometimes headache-inducing, ...
7 votes

How can I update a popup while shown?

While your Operator.check(...) method returns True the popup will redraw. Simple return True method used in ...
batFINGER's user avatar
  • 83.5k
7 votes
Accepted

How can I pass arguments to an Operator inside a Macro Operator?

Macro.define("TRANSFORM_OT_translate") returns a OperatorMacro which has a properties ...
ideasman42's user avatar
6 votes
Accepted

How to access all selected files from a file selector in Python?

You can access files for any operator using the file-selector, by defining a files collection of OperatorFileListElement. Here is a complete example of an operator that opens a file selector and ...
ideasman42's user avatar
6 votes

Python: Operator Undo Method

Blender's undo system works by saving the blend file to memory, and loading it to perform the undo. If your operator doesn't fully undo, you're probably calling other operators from within its code. ...
dr. Sybren's user avatar
  • 7,129
6 votes
Accepted

How to assign PointerProperty in Operator through UI?

Aafter continuing researching, apparently operators can only take basic properties (e.g. string, bool, int, float, collections of the property types just mentioned), and PointerProperties only work if ...
S. Magnusson's user avatar
  • 1,483
6 votes
Accepted

How can I display a FloatVector without it being editable by the user?

You can disable the row (makes it read-only) and set emboss to False for example: ...
Gorgious's user avatar
  • 29.3k
6 votes
Accepted

How to control spacing/alignment of Label + Horizontal Enum Property?

Just set layout.use_property_split property in your draw method to True: ...
brockmann's user avatar
  • 12.3k
6 votes
Accepted

How to pass a bpy.data.objects / bpy.data.materials / etc to an operator from the layout?

Add context members for your op to use. Would assume you tried object: PointerProperty(type=bpy.types.Object) only to get the error message saying you can't ...
batFINGER's user avatar
  • 83.5k
6 votes

A comprehensive list of operator overrides

I'm still working on my script that helps me to detect what elements a context override requires, but I guess I might as well share it now and update it later... Making context copy First, prepare a ...
Markus von Broady's user avatar
6 votes
Accepted

Align & Scale Light (Portal) to Face

A Python script to do that. The tricky part (I think) is to make it work whatever the face is: orientation, number of vertices, concavities... I guess that in this kind of cases, we want the light to ...
lemon's user avatar
  • 53k
5 votes
Accepted

Incompatible operator return type in simple empty adding operator

OK, I realized that I made a typo/mistake. In the MarkerAdd operator, in the function execute I've put ...
piotao's user avatar
  • 1,387
5 votes
Accepted

How to store variable and use it as property in panel?

Using both a pointer, property group setup. The tile width, scene.iso_render.tile_width, is passed to the operator. You could bypass defining and using the ...
batFINGER's user avatar
  • 83.5k
5 votes

Why avoid bpy.ops?

Apart from what's been said already, operators also create undo steps. This means that every time you execute an operator, the entire blend file is saved in memory. This is one of the reasons calling ...
dr. Sybren's user avatar
  • 7,129
5 votes

Scripting -- Can't figure out how to use correct contexts?

I encountered a similar error recently, and thought of adding another solution in addition to the one from @sambler , for the sake of posterity. The line of code that caused the exception was: ...
Tedy Kanjirathinkal's user avatar
5 votes

Making Property sliders act similar to Operators

You can use the 'update' function value that can be assigned to the property's definition: Update function is triggered each time the slider's value is changing. ...
lemon's user avatar
  • 53k
5 votes
Accepted

Operator Search: 'Free Data' not available in Blender 2.9 anymore?

The default behavior of the Operator Search dialog in 2.9x is to only list the operators that can be found in menus. In order to search for all registered operators, you currently have to enable the ...
Robert Gützkow's user avatar
  • 25.4k
5 votes

Change the "OK" button name in dialog-boxes?

Unfortunately this isn't something you have any control over. The window_manager.invoke_props_dialog function is defined in C here, and ultimately uses the ...
Chris Hayes's user avatar
5 votes
Accepted

How can I add a panel to the properties area of the file browser?

You would have to add a draw() method along with a pass statement to the operator in order to skip drawing and declare a ...
brockmann's user avatar
  • 12.3k

Only top scored, non community-wiki answers of a minimum length are eligible