Skip to main content
The 2024 Developer Survey results are live! See the results

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.

Filter by
Sorted by
Tagged with
50 votes
2 answers
48k views

poll() failed, context incorrect? - Example: bpy.ops.view3d.background_image_add()

I keep on getting context errors in the Blender Python API. I don't understand the issue of the context in the API, how do I know which is the correct context? Thanks!
Jonathan's user avatar
  • 601
57 votes
2 answers
61k views

How to create a custom UI?

I was watching this video on making a custom UI tab using Python, and in the line from bpy.types import Menu, Panel, UIList, I see the names of objects that look ...
DragonautX's user avatar
  • 1,316
47 votes
3 answers
28k views

Control Cycles/Eevee material nodes and material properties using python?

How can I define the different properties of an Cycles/Eevee material? Such things as glossy, glass, diffuse, RGB-color, emissive via python scripting?
binaryBigInt's user avatar
  • 1,047
38 votes
2 answers
15k views

Python performance with Blender operators

In my script, I have for loop over many cube objects (~1000) and the treatment is very slow. Looking more in details, I notice that in the same amount of loops: if ...
Salvatore's user avatar
  • 757
70 votes
10 answers
60k views

Using 3rd party Python modules

I'm currently developing a script for Blender to handle Mesh Frequency Decomposition. The script is nearly complete, but i need one more thing: The SciPy library to compute eigenvalues and ...
Gouwi's user avatar
  • 701
100 votes
10 answers
129k views

Where does console output go

I'm trying to debug a Python script by placing a print("foo=" + foo) statement in my code. But where does the output appear? It doesn't appear on the Python ...
P i's user avatar
  • 3,961
27 votes
1 answer
14k views

Create an interface which is similar to the material list box

How can I make a Interface which is similar to the Material-Interface within Blender via Python? It should look like these. Could you guide me to the right direction? I don't think it's in bpy.ops, ...
Hamburml's user avatar
  • 957
34 votes
4 answers
6k views

Why avoid bpy.ops?

Simple and maybe stupid question: I was reading this lot of time, that "you should avoid using bpy.ops, or "instead of ...
Zéiksz's user avatar
  • 1,979
68 votes
5 answers
41k views

How to pass command line arguments to a Blender Python script?

Let's say we have a Python script my_script.py that does some data processing with Blender. This script accepts some arguments (e.g. ...
BenC's user avatar
  • 783
11 votes
3 answers
4k views

How do I get a mesh data-block with modifiers and shape keys applied in Blender 2.8?

I'm trying to update an exporter to work with Blender 2.8 but can't seem to get a mesh data-block modified by modifiers or shape keys. It always gives me the base mesh. I'm currently using ...
Somebody285's user avatar
41 votes
1 answer
51k views

How to assign a new material to an object in the scene from Python?

How can I assign a new material to an object in the scene via Python?
binaryBigInt's user avatar
  • 1,047
15 votes
2 answers
4k views

Is it possible to make a sequence of renders and give the user the option to cancel the process through the UI at any given time?

I'm trying to make a script where I have to render several images of the same scene at the same frame, and write to disk with appropriate names. The problem is that although this works fine with a non-...
Chaos's user avatar
  • 642
17 votes
1 answer
4k views

How to pass multiple operator properties via UI layout?

Basically, I want to have a single operator which can do multiple things, based on some attributes values. ...
Polosson's user avatar
  • 6,574
15 votes
1 answer
12k views

How to create a Folder/File Dialog?

So I need to allow the user of my script to choose a directory that contains images, and then run my script on each image. I already have my script made here. I looked at this question already, but ...
doomslug's user avatar
  • 1,819
10 votes
1 answer
9k views

How to Link/Append a data-block using the Python API?

I'm searching a way to append a group in Python. It should behave exactly like the Append function (ShiftF1) works, all objects should be local and editable. The idea is to append a character (with ...
Boris's user avatar
  • 625
92 votes
4 answers
91k views

How can I run blender from command line or a python script without opening a GUI?

I'm interested in using Blender for producing images, 3d files, or calculating geometry on a server. Can I make blender run a python script without opening a GUI? If not, can I incorporate Blender's ...
BenjaminGolder's user avatar
25 votes
2 answers
15k views

TypeError: Element-wise multiplication: not supported between 'Matrix' and 'Vector'

Blender 2.8 produces the following error whilst multiplying a combination of matrices and vectors ...
batFINGER's user avatar
  • 84.6k
14 votes
2 answers
2k views

A comprehensive list of operator overrides

I feel like I'm always spending far too much time playing scripting whack-a-mole whenever I want to override an operator in one of my scripts. I'd like to build a comprehensive one-stop-shop list for ...
Gorgious's user avatar
  • 31.6k
46 votes
11 answers
59k views

How to install Pip for Blender's bundled Python?

Blender comes with Python, and includes a stand-alone Python executable. However pip is not part of the official Python distribution so it needs to be added separately. How do you setup ...
ideasman42's user avatar
  • 47.6k
13 votes
1 answer
12k views

How to call a confirmation dialog box?

I have a button in my menu named "New File" as shown: and I want when I click on the "New File" button to imitate what the Blender File->New does, where a check message box appear first confirming ...
Tak's user avatar
  • 6,323
32 votes
1 answer
18k views

What do operator methods do? (poll, invoke, execute, draw & modal)

I've seen the functions called poll and invoke used in scripts. I'm curious what these are for and when they are called.
TARDIS Maker's user avatar
  • 5,762
31 votes
2 answers
14k views

Is it possible to create image data and save to a file from a script

I'm currently trying to extract textures from a binary file, and ideally I'd like to save each texture to a file or embed in the .blend file. However, before saving ...
MrFlamey's user avatar
  • 3,879
6 votes
3 answers
6k views

Script to render one object from different angles

I'm new to Blender. I'm currently working on a 3D reconstruction project using neural networks. I need to create my data set. Therefore I need to render a 3D body scan from different angles and save ...
wissal saihi's user avatar
22 votes
6 answers
36k views

How to convert coordinates from vertex to world-space?

How do I convert from object-space to world-space? I suspect it is: vert_os = obj.vertices[foo] vert_ws = vert_os.getPositionFromMatrix(obj.matrixWorld) but ...
P i's user avatar
  • 3,961
16 votes
3 answers
14k views

How to get world-space matrix of any pose bone?

Is there a command for getting world-space matrix of pose bones, same as obj.matrix_world for objects? I found pose_bone.matrix, ...
Roman Volodin's user avatar
10 votes
2 answers
4k views

Object selection box with eyedropper

How to add an eyedropper functionality to prop_search in my addon? ...
Mikhail Rachinskiy's user avatar
22 votes
5 answers
33k views

How to join objects with Python?

I try to do this: bpy.ops.object.select_all() bpy.ops.object.join() in my script. It selects all the stuff like CtrlA but fails on ...
Zéiksz's user avatar
  • 1,979
21 votes
6 answers
16k views

How to access Render Result pixels from python script?

Render Result exists in bpy.data.images["Render Result"] but it contains no data. Also bpy.data.images["Render Result"].size[0] ...
Hatoru Hansou's user avatar
10 votes
2 answers
16k views

Create model from XYZ data points

I'm trying to create a 3D heat map model out of data that I have from a csv file. I have a few thousand data points with XYZ coordinates. I'm able to import the data into blender as a point cloud ...
DanielP's user avatar
  • 103
31 votes
3 answers
55k views

Python: Selecting object by name in 2.8

The following: bpy.data.objects['Cube'].select = True bpy.context.scene.objects.active = bpy.data.objects['Sphere.017'] don't work in Blender 2.8, they did in 2....
Michael Teiniker's user avatar
17 votes
3 answers
14k views

Align Object to Vector using python

I am trying to rotate an object using python, inline with a vector which gives me the direction I want (based on the difference between the last two coordinates of the curve I generated). I therefore ...
Batwam's user avatar
  • 325
12 votes
3 answers
6k views

How to find all objects in the Camera's view with Python?

I have a scene with a many objects and one camera. I would like to select the objects that the camera sees, even partially. Is there a way to do that in Python that accounts for the objects bounds? ...
nantille's user avatar
  • 819
7 votes
1 answer
2k views

Create keyboard shortcut for an operator using python?

How can I create a keyboard shortcut for a specific operator with using the python API?
BlenderUser123's user avatar
6 votes
2 answers
12k views

How to add modifiers using python script and set parameters?

I've found some code that could add a modifier but none can set parameters like Octree.
Claire's user avatar
  • 95
58 votes
5 answers
84k views

Python: How to completely remove an object

How can I completely remove an object (for example a camera) using python scripting? Using something like: scene.objects.unlink(camera) Does not work, since it ...
Jan Rüegg's user avatar
28 votes
1 answer
31k views

Blender 2.8 API, python, set active object

I'm trying to amend an addon that I made for Blender 2.7X to work with Blender 2.80. The problem is with bpy.context.scene.objects.active = some_object This is ...
Georges D's user avatar
  • 5,042
21 votes
3 answers
14k views

Is it possible to print to the Report window in the Info view?

I wonder if it is currently possible to print or send messages to the Report window in the Info view? this would be quite useful sometimes.
zeffii's user avatar
  • 39.7k
9 votes
2 answers
5k views

Limit "prop_search" to Specific Types of Objects

Currently working on a piece of custom UI that contains an object selection box. layout.prop_search(scene, "myselection", scene, "objects") I'm wondering how I ...
BlenderBro's user avatar
  • 1,201
3 votes
2 answers
15k views

How to read a csv file and use the values as x and y points in blender?

How can i use the value in column 'lon' and 'lat' as the position of my uv_sphere? For example,read the values from line 4, (116.4559081, 39.9139083), and make these 2 numbers as my uv_sphere x and y ...
JeffFederick's user avatar
30 votes
1 answer
11k views

How to implement custom icons for my script/addon?

Is it possible to use different icons other than the default set and how?
Jaroslav Jerryno Novotny's user avatar
20 votes
1 answer
10k views

Finding vertices in a Vertex Group using Blender's Python API

Is there an easy way to get the vertices in a vertex group? The only way I've found is pretty brute-force - e.g., to find the vertices of object obs[i] in group "e"...
Jabberwock's user avatar
5 votes
2 answers
4k views

Add camera at random position through Python

I am using Blender for the first time. Currently, I have a basic scene with a camera and some light sources present. What I would like to do is to add a second camera that is located at a random ...
JNevens's user avatar
  • 153
5 votes
2 answers
3k views

Start script on open blender file

I have written up a script for my model. But there is a bit of a problem with it. As in I have to run the script every time I open the file. I want the script to run automatically when I open the ...
Raspberry's user avatar
  • 425
3 votes
2 answers
3k views

Internal "get/set" function of property?

Here is my test code and picture: ...
Heixue's user avatar
  • 117
17 votes
1 answer
4k views

How to run an external command, showing its progress without locking Blender? (Escape to cancel for eg)

Currently if you run an external process from Python the command and locks Blender until it finishes, eg:subprocess.check_output(["sleep", "2"]). Whats the best ...
ideasman42's user avatar
  • 47.6k
16 votes
3 answers
17k views

Update viewport while running script

I have a script, which creates multiple objects through a loop. However, the script freezes the viewport until it is done. Instead, I would like every object to be seen in the viewport one by one as ...
dwitvliet's user avatar
  • 409
11 votes
2 answers
7k views

How do I override context for bpy.ops.mesh.loopcut?

I am trying to use loopcut in a python script in Blender 2.71. I have tried using the following code from "Loop cut and slide using python script in blender": ...
Mike N.'s user avatar
  • 360
38 votes
2 answers
34k views

How to get the directory of open blend file? (from Python)

What's the best way to get the full directory of the current Blender file in Python? It should be cross-platform.
Garrett's user avatar
  • 6,596
30 votes
2 answers
64k views

How can I get vertex positions from a mesh?

I want to read the vertex x and y coordinates with a script or a function. How can I do that? The MeshVertex appears to have ...
B Newmark's user avatar
  • 1,240
26 votes
10 answers
16k views

How to build Blender as a Python module?

I have seen this question now many times and every question here and on other forum points to build blender as python module experimental tutorial by ideaman42. Now sadly a lot of answers are invalid ...
Hakaishin's user avatar
  • 577

1
2 3 4 5
53