Questions tagged [python]

Python is an object-oriented programming language. In Blender, it is used as a general purpose scripting language and to create add-ons to extend Blender's functionality.

3,524 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
47 votes
1 answer
2k views

Custom trackpad pan/zoom/rotate behavior add-on

I'm trying to write an addon to customize the trackpad panning, zoomimg, and rotating gestures, but can't find a way to read the actual trackpad parameters for position and so on. The properties in ...
  • 4,421
14 votes
0 answers
889 views

How to bring the context "back" after running read_homefile()?

When I run import bpy bpy.ops.wm.read_homefile() and then I replace the above with this (in the same text data block) ...
  • 881
11 votes
1 answer
544 views

Set Active FCurve in Graph Editor through python

I'm trying to set an FCurve in the Graph Editor to "Active" through python. In the API FCurves don't actually have an "Active" property, but manually click-selecting a channel or keyframe on an ...
  • 603
10 votes
1 answer
395 views

How can I get a list of currently running modal operators?

Here I found a working solution using ctypes which allows to find out if any modal operator is currently running. I am not good in C and don't understand how it works. But I'm sure someone does, so is ...
9 votes
0 answers
161 views

Play/animate images, spritesheets or video files in 'template_icon_view'

I want to "play" some animation in this UI space, the template_icon_view: I can load all the images I want, for example: I know that the gif format is ...
  • 2,197
9 votes
0 answers
512 views

Save screenshot (bge) without writing to disk

This is a little odd but I need to save a screen-shot as an array (numpy array for eg) without writing to disk. The idea here is to create and then call the array once per frame in an external script ...
  • 301
8 votes
0 answers
321 views

Blender on Windows is skipping python script. (brenda on windows)

We've been using Brenda for quite some time now for rendering architectural stills. Since our editing stations are doing nothing at night, I started making a desktop app that allows you to pick jobs ...
7 votes
0 answers
381 views

Operator tooltip from layout text

The concept is to make a panel layout that emulates the workspace (screen) layout. While testing I have set all the buttons to be the Splash Screen operator. An image of how this looks for five ...
  • 80.2k
7 votes
0 answers
506 views

Update function for NodeSocket?

How do I set a callback for socket input change (value or link change) when having a custom node? I have a socket defined like: ...
  • 167
7 votes
0 answers
539 views

Is there a low level alternative for bpy.ops.object.convert(target='CURVE')?

(Note: Somebody asked there nearly the same question as me and got a very nice answer. However, this was to convert an object to a mesh. I have exactly the same context as this person but I want to ...
  • 183
6 votes
0 answers
108 views

Numpy optimise mesh edges length calculation

To improve my very rudimentary numpy knowledge am going to ask a number of optimise my numpy questions here on BSE Can find the length of each edge in a mesh using ...
  • 80.2k
6 votes
1 answer
192 views

How to display an image in my custom node

I have a custom node and I want it to be able to display an image. I know that the node has a parameter show_preview and if you enable it, no image appears.
  • 131
6 votes
0 answers
477 views

Scale operator icon OR make template_icon clickable

I am trying to present the user with a gallery view to select a item from the thumbnails. Ideally, they click a button, are presented with the gallery view, and with a single click choose the item. I ...
  • 183
6 votes
0 answers
782 views

Override context for operator called from panel

I have an operator, “my_operator”, that is called from a panel, as follows: ...
  • 276
6 votes
0 answers
852 views

Can Blender automatically reload external script files when they are changed?

I came across this question: Is it possible to run a script from an external editor without reloading the file? Which also was asked over here in a similair format: Workflow for developing add-on/...
  • 496
6 votes
1 answer
341 views

How to speed up loading of custom external icons?

I have developed a little addon that provides icon button in the node editor. We have 80 node items. And so i have 80 external icons to load. I use custom_icons.load for that. The problem is, every ...
  • 1,988
6 votes
1 answer
2k views

How to update compositing nodes via script?

I create some nodes in compositing via python script: ...
  • 171
5 votes
0 answers
133 views

Finding which addon an operator belongs to

A recent question / answer involves what looks like an overridden operator bpy.ops.object.align() differing from the documented default, how do we find which addon(...
  • 80.2k
5 votes
0 answers
308 views

How do I change the width of operator popup?

I've done this simple operator taken from templates. How to change operator GUI width? I tried scale_x and ui_units_x but no ...
5 votes
0 answers
469 views

Is there a low level alternative for bpy.ops.mesh.separate()?

I am dealing with a great model, I have a problem, I want to divide it by parts, but bpy.ops.mesh.separate(type = 'LOOSE') seems to have a big problem, that is not ...
  • 1,038
5 votes
0 answers
134 views

How to access Density/Flame grid via Python in 2.82 (Mantaflow)

Does anyone know how do I access the density/flame grid for the new Mantaflow fluid simulation engine in Blender 2.82? The old path still exists: ...
5 votes
1 answer
1k views

How to wait for an operation - to another operator - to complete within an operator (import_scene)

Besides the point but why is this not working as a default stack is expected to work? I'm trying to get an operator to call another operator and wait for the operator's response before proceeding. ...
5 votes
0 answers
3k views

Why does bpy.ops.object.mode_set(mode='EDIT') switch to the Object Mode when executed?

I wrote a python script that modifies an existing blender armature that I have and some of these modifications include some commands that are only possible in Edit Mode. I know that depending on what ...
  • 51
5 votes
0 answers
578 views

PyOpenGL and VBO Indexes

Long story short, I'm trying to do a modal handler that draws using OpenGL into the viewport. Immediate mode through BGL works fine, but is dog slow. I tried using VBOs through BGL but there seems to ...
  • 606
5 votes
1 answer
307 views

"Search for unknown operator" On Start-Up After Removing Module and Shortcuts

For lack of a less drastic alternative, I created a whole module just for setting bpy.context.window.screen to a specific screen, since ...
  • 182
5 votes
0 answers
141 views

What do all of the mode enums mean?

What do all the various mode constants in blender operators documentation do? bpy.ops.object.duplicate(linked=False, mode='TRANSLATION') - Duplicate selected objects Parameters: ...
5 votes
0 answers
455 views

How does 'Align Active Camera to Selected' decide where to place the camera?

Thanks to this answer, I'm using bpy.ops.view3d.camera_to_view_selected() to automatically place a camera so that it frames the selected object for rendering. But ...
5 votes
0 answers
216 views

How can I derive from an existing Operator in Python?

When creating a new Blender Operator, you'll derive the class from bpy.types.Operator, like this: ...
  • 10.9k
5 votes
0 answers
862 views

accessing Blender objects from external Python IDEs

I would like to manipulate Blender objects from Spyder (not using the internal Python editor). Basically I would like to have Blender running and Spyder running as well, and then interactively access ...
  • 151
5 votes
1 answer
257 views

Cannot mix .user and .addon keyconfigs in register()

I've been messing around with keymaps lately and I've come across behavior that doesn't make much sense to me. I am searching the current keyconfig for a specific keymap item, removing it, then adding ...
  • 1,533
5 votes
0 answers
387 views

Does anyone have an example of template_curve_mapping?

I'm doing some test with template_curve_mapping. I have write this code: ...
  • 462
5 votes
0 answers
658 views

Adding sliders from UI to pie menu

I've seen some sliders working in pie menus but the one I'm trying to add to my pie script isn't showing up. Its the 'autosmooth normals' slider from the Object Data tab, under Normals (in the ...
  • 113
5 votes
0 answers
505 views

Hide filter options in UIList

I want the UIList to not show the filter options (inkl. the plus button). I've use following flag: self.use_filter_show = False The flag disables the filters ...
  • 693
5 votes
0 answers
754 views

Converting an obj sequence to a .bobj fluid sim cache?

I'm wondering if there is any way to accomplish turning an obj sequence exported from realflow into a .bobj fluid cache that I could then trick blender into loading as a native fluid sim cache. So far ...
4 votes
0 answers
53 views

Detect when an Asset has been applied (dropped in the viewport)

So far this has been the way I check if World asset has been dropped in the viewport: ...
4 votes
0 answers
163 views

How to read out every camera object from blend file? (with blendfile.py)

I have a multiple scenes in a blend file, each scene has multiple camera objects. Is there a way to read out every camera object for each scene? I can read every camera in the blend file, but I don't ...
4 votes
0 answers
53 views

The documentation says frame_change_pre is NOT the ‘before the frame changes’ event. What exactly is it then?

I would have imagined that frame_change_pre is the event that happens, well, before the frame changes. Silly me! The documentation states (emphasis mine): Called ...
  • 762
4 votes
0 answers
100 views

How to build an autocomplete search to search for some words in memory?

I am using a StringProperty to assign a list of (Singles) words through manual entry, and I was wondering if you could build some sort of autocompletion for a StringProperty. Suppose I have a list of ...
  • 1,038
4 votes
0 answers
113 views

Is there a recommend way to repair or recreate a valid context after using `bpy.ops.wm.read_factory_settings(use_empty=True)`?

I am not sure if this is a bug or intended behavior, but using bpy.ops.wm.read_factory_settings(use_empty=True) reduces the context to a state where is cannot be ...
  • 41
4 votes
0 answers
69 views

Call function when collections are modified

I am writing an addon and I would like to update some of the properties whenever collections change: a new collection is created, a collection is removed, a collection is renamed. I am trying to use ...
  • 141
4 votes
1 answer
740 views

How to get frame-by-frame object location in Blender 2.8+

I am trying to get the frame-by-frame location of the softbody physics simulation (collision of softbody cube with a plane). I am incrementing the frame of the simulation using ...
4 votes
0 answers
161 views

Strategy for script-generating a buckled honeycomb lattice mesh (hex faces) for animating 2D materials?

In this post I show how one can script-generate a square lattice with buckling. By scripting it there's memory of each vertex's identity which can be used later to animate certain behaviors. When ...
  • 2,647
4 votes
0 answers
125 views

Object Picker Modal Operator?

I saw this question this morning and i'm also quite interested in a Picker modal operator, so I did tinker a bit and achieve a somewhat beginning of a working code but I encountered some problems ...
  • 1,591
4 votes
0 answers
127 views

How to dynamically load a .dat icon (toolshelf icon)?

Using documentation here 2.80/Python_API/UI_DESIGN, I've managed to create a custom .dat tool shelf icon for use with an operator in my addon. The icon will display from my addon when registered from ...
4 votes
0 answers
167 views

How to delete element from UIList with a button, when the element is clicked?

I am making a simple addon, that keeps information about location of group of objects at different frames. Every time I make a keyframe on location for a group of objects, where each object has prefix ...
  • 93
4 votes
0 answers
3k views

Blender 2.9 python Operator bpy.ops.object.mode_set.poll() failed, context is incorrect

I'm a bpy beginner and i'm facing a error with python scripting on the line ...
  • 41
4 votes
0 answers
56 views

Instancing a space theme with a draw callback

In a somewhat tongue in cheek answer to https://blender.stackexchange.com/a/197340/15543 have come across the possibility of having one instance of a 3d view showing a different theme than another. ...
  • 80.2k
4 votes
0 answers
2k views

How to delete drivers via python?

I want to delete all drivers on object in Blender 2.8. I am quite new to the scripting and the only code I have found is this: ...
  • 41
4 votes
0 answers
2k views

When to use ".ensure_lookup_table()"?

For modifying meshes (in the hereunder example removing vertices), I use the script as follows: ...
  • 41
4 votes
0 answers
213 views

Recover python script after blender crash

When writing a script and Blender crashes I lose the changes in my script? If blender crashes, I can only get the scripts I've saved manually saved (via Alt+S or Edit > Save). Often I will do Run ...
  • 141

1
2 3 4 5
71