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
46
votes
2answers
42k 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 ...
45
votes
1answer
33k 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!
43
votes
3answers
25k 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?
30
votes
2answers
11k 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 ...
62
votes
9answers
47k 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 ...
77
votes
8answers
82k 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 ...
57
votes
4answers
29k 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. ...
23
votes
1answer
10k 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, ...
29
votes
4answers
4k 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 ...
9
votes
2answers
2k 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 ...
8
votes
1answer
7k 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 ...
35
votes
1answer
35k 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?
12
votes
1answer
8k 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 ...
14
votes
1answer
2k 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. ...
10
votes
1answer
7k 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 ...
18
votes
1answer
9k 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 ...
10
votes
2answers
12k 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 ...
10
votes
2answers
3k 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-...
78
votes
3answers
61k 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 ...
28
votes
2answers
11k 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 ...
21
votes
6answers
29k 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 ...
15
votes
3answers
9k 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, ...
25
votes
1answer
23k 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 ...
9
votes
2answers
2k views

Object selection box with eyedropper

How to add an eyedropper functionality to prop_search in my addon? ...
24
votes
1answer
12k 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.
23
votes
3answers
32k 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....
19
votes
5answers
12k 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] ...
5
votes
3answers
4k 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 ...
3
votes
2answers
10k 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 ...
3
votes
1answer
1k views

Internal "get/set" function of property?

Here is my test code and picture: ...
15
votes
3answers
11k 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 ...
48
votes
5answers
59k 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 ...
18
votes
3answers
9k 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.
4
votes
2answers
2k 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 ...
1
vote
1answer
418 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?
3
votes
2answers
2k 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 ...
16
votes
1answer
3k 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
1answer
6k 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"...
8
votes
2answers
4k 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? ...
40
votes
8answers
34k 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 ...
17
votes
4answers
23k 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 ...
15
votes
2answers
11k 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 ...
14
votes
7answers
2k views

How to find the number of loose parts with Blender's Python API?

I want to find out how many loose parts a mesh has using Python, i.e. write a function that takes a mesh object as an argument and returns an int. So far I haven't found a way to access this ...
19
votes
9answers
12k 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 ...
8
votes
1answer
7k views

Dynamic EnumProperty by type of selection

Iam searching for a method to get a EnumProperty by the type of the object (Lamp, Geo, Camera) thats selected in the viewport. E.g. If the selected object is a lamp, it would be nice the enum ...
12
votes
4answers
4k views

How to keyframe mesh vertices in Python

I'm updating all the vertex coordinates of a mesh frame-by-frame in python and need to animate but can not figure out how. Here is a small abstracted script - the python isn't pretty, but it makes an ...
2
votes
1answer
769 views

Create curve from Numpy Array using Python

I have looked through previous questions on this and many other boards and I cannot seem to find a previous answer. I have a largish Numpy generated ndarray that represents a harmonograph output (...
23
votes
1answer
8k views

How to implement custom icons for my script/addon?

Is it possible to use different icons other than the default set and how?
16
votes
4answers
7k views

How can I store and retrieve a custom list in a blend file?

I am trying to create a script that will allow me to generate a list and store it in the blend file. The list starts out blank and then strings get added to the list, resulting in: ...
13
votes
6answers
11k views

How to find if a point is inside a mesh?

I need a python script that would help me determine if a point is inside a cylindrical mesh. I tried the .pointInside(point, selected_all=False) but it is deprecated in the newer versions of blender ...

1
2 3 4 5
44