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 ...
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....
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'...
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 ...
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:
...
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.
...
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):
...
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
...
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 ...
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 ...
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 '...
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, ...
Community wiki
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 ...
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 ...
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 ...
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. ...
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 ...
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:
...
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:
...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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:
...
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.
...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
operator × 479python × 397
scripting × 185
add-on × 68
interface × 60
properties × 52
panel × 37
shortcut × 14
mesh × 10
error × 10
objects × 9
transforms × 9
3d-view × 8
customization × 8
rendering × 7
grease-pencil × 7
modeling × 6
modifiers × 6
import × 6
command-line × 6
bmesh × 6
animation × 5
export × 4
video-sequence-editor × 4
uv × 3