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.
2,648
questions
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!
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 ...
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?
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 ...
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 ...
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 ...
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, ...
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 ...
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. ...
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 ...
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?
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.
...
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 ...
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 ...
92
votes
4
answers
90k
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 ...
14
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-...
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
...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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, ...
10
votes
2
answers
4k
views
Object selection box with eyedropper
How to add an eyedropper functionality to prop_search in my addon?
...
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 ...
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] ...
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 ...
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....
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 ...
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?
...
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?
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.
58
votes
5
answers
83k
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 ...
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 ...
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.
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 ...
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 ...
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?
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"...
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 ...
3
votes
2
answers
3k
views
Internal "get/set" function of property?
Here is my test code and picture:
...
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 ...
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 ...
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":
...
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 ...
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.
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 ...
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 ...