Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
84 votes
3 answers
66k 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 ...
user avatar
81 votes
3 answers
54k views

How can I quickly generate / create a large city without modeling it all by hand?

I am trying to create an urban open-world environment in Blender that would be about one square kilometre in size. To avoid having to model hundred of individual buildings, I am looking for a way to ...
user avatar
  • 913
81 votes
8 answers
89k 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 ...
user avatar
  • 3,671
69 votes
5 answers
23k views

Is there a tool for scientific visualization using Blender?

Is there an interface or API that allows using Blender as a tool for mathematical and scientific visualization? It should allow Blender to read in data (a la gnuplot or matlab, perhaps using scipy) ...
user avatar
  • 792
65 votes
9 answers
51k 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 ...
user avatar
  • 651
61 votes
5 answers
31k 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. ...
user avatar
  • 713
52 votes
2 answers
46k 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 ...
user avatar
  • 1,226
52 votes
5 answers
65k 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 ...
user avatar
46 votes
1 answer
36k 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!
user avatar
  • 561
45 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 ...
user avatar
  • 4,361
44 votes
3 answers
73k views

Selecting an object via scripting?

As shown below, I have 2 nested spheres, each with a different material (inner = "1", outer = "2"). Ultimately, I need to select the inner sphere (material "1") via ...
user avatar
44 votes
3 answers
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?
user avatar
41 votes
8 answers
39k 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 ...
user avatar
  • 44.4k
36 votes
1 answer
39k 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?
user avatar
35 votes
2 answers
20k views

Can I run a Python script step by step in Blender?

Can I run a python script step by step with normal blender, a build, external software or an addon? I'm developing a script (town generator) and I want to to execute the code step by step like a ...
user avatar
  • 3,193
32 votes
2 answers
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 ...
user avatar
  • 687
32 votes
3 answers
19k views

Is the Blender GUI package available for other programs?

I really love the look of Blender's built-in GUI, and would potentially like to use these tools in some of my other Python applications. As I understand it, Blender created all of these tools from ...
user avatar
  • 11.2k
31 votes
4 answers
5k 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 ...
user avatar
  • 1,859
30 votes
2 answers
12k 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 ...
user avatar
  • 3,679
29 votes
2 answers
25k 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.
user avatar
  • 6,276
28 votes
1 answer
13k 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.
user avatar
  • 5,502
28 votes
2 answers
47k 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 ...
user avatar
  • 1,170
27 votes
1 answer
26k 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 ...
user avatar
  • 4,544
27 votes
1 answer
1k views

Closing "Fibonacci's Hole"

Creating a sphere using the points defined by Spherical Fibonacci Mapping. For the most part it is easy to "skin" by using two consecutive fibonacci numbers as steps to loop on the index. And get ...
user avatar
  • 77.7k
26 votes
3 answers
38k 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....
user avatar
26 votes
1 answer
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?
user avatar
25 votes
9 answers
22k views

Efficient way to get selected vertices via python (without iterating over the entire mesh)

What's the best/fastest way to construct a list of selected vertices for a mesh object in python? I want to avoid iterating over every vertex in the mesh if possible, since that seems like a really ...
user avatar
  • 3,102
25 votes
0 answers
1k views

Property Panel Custom Popup Menu when user presses hotkey over an input field

is it possible to trigger this kind of menu: in the property panel when I press a hotkey over a button/input field? I want to specifically,when the user presses a specific hotkey when over an input ...
user avatar
24 votes
1 answer
11k 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, ...
user avatar
  • 917
23 votes
13 answers
27k views

How can I add a cube?

I am trying to add cubes to my scene. I'm sure there are lots of ways to get a cube into the scene (but for the purposes of this question, I have no idea what they are) - Are there any ways to add a ...
user avatar
23 votes
5 answers
16k views

How to know which object is using a material

How to know which object is using a material. I know that a material is used 4 time -> picture under: I'm searching a solution with python and I'm blocked here : ...
user avatar
  • 3,193
23 votes
3 answers
14k views

Is there a way to restart a modified addon?

I'm currently twiddling with an old addon and insert some print statements for debugging. Currently I'm restarting Blender each time to see the new messages. Is there a way to 'refresh' an already ...
user avatar
  • 37.4k
23 votes
2 answers
5k views

Blender UI Multithreading Progressbar

The following question might've been asked several times, but I've found no satisfactory answer. Short question: How can I show progress of background task in Blender UI? Explanation: I have a ...
user avatar
  • 801
22 votes
4 answers
22k views

Add Nodes to Material with Python

I have edited a script that creates some nodes, but the only problem is, it always created a new material. I want it to either add the nodes on the existing material, or a pre-defined material. Here ...
user avatar
  • 2,002
22 votes
3 answers
16k views

Pointing the camera in a particular direction programmatically

I'm trying to use Python to place a camera. I know the camera's location, and the forward and up vectors for the camera (i.e. the direction it's pointing and its orientation). How do I do this? I ...
user avatar
22 votes
4 answers
30k views

How to show to the user a progression in a script?

I'm making an python script which create a lot of object and this could take a lot of time. My question is how to show to the user of my script, the "progression" of the script? For now I print an ...
user avatar
  • 3,193
22 votes
5 answers
18k views

How to set cursor location, pivot_point in script?

I am trying to set a cursor location and pivot point with bpy.types.SpaceView3D.pivot_point='CURSOR' bpy.types.SpaceView3D.cursor_location = (0.0, 0.0, 0.0) and ...
user avatar
  • 3,112
22 votes
9 answers
13k 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 ...
user avatar
  • 507
22 votes
2 answers
10k views

Blender sets Compute Device (CUDA) but doesn't use it for actual render (on EC2 GPU Instance)

I'm trying to set up some automated render servers on EC2 using their GPU instance type (g2.2xlarge). I'm running blender in the background with a python script that renders the image I want and saves ...
user avatar
  • 323
21 votes
6 answers
31k 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 ...
user avatar
  • 3,671
21 votes
4 answers
7k views

Convert Curves to Grease Pencil?

I'd like to know if there's a way/add-on to convert curves to Grease Pencil strokes? I know you can convert in the other direction, but I can't find anything to create Grease Pencil strokes from ...
user avatar
21 votes
2 answers
648 views

Which modules are guaranteed to be present in Blender's Python?

Which modules are guaranteed to be included in Blender's custom Python build?
user avatar
20 votes
1 answer
10k 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 ...
user avatar
  • 77.7k
20 votes
4 answers
13k views

What programming languages can I use in Blender?

What version of Python does Blender use and are other languages available? Also, does Python work the same in Blender as when you write console applications or when working with Pygame or are there ...
20 votes
6 answers
13k 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] ...
user avatar
20 votes
4 answers
39k views

How to get Python multiprocessing module working on windows?

I am trying to run a script within Blender that utilizes multiprocessing module. According to documentation it is possible to use it ( see note at the end of "...
user avatar
  • 702
20 votes
0 answers
852 views

How to make a dynamically expanding menu in Blender?

Say we want to navigate a tree structure without knowing all the data ahead of time, is it possible to do this in Blender? For example, a menu which dynamically loaded a directory hierarchy from the ...
user avatar
  • 44.4k
19 votes
4 answers
12k views

Where can I find what version of python is bundled with certain Blender versions?

The question is where I can reliably find the information on which python version is bundled with a certain Blender release (like 2.72b at the moment)? I need to find the major and minor version ...
user avatar
  • 413
19 votes
5 answers
22k views

Importing python modules and text files

I am new to blender, but not python, and have been asked to create a user-input dependent, stylized animation of a protein network I am working with: text document >> information processed by python-...
user avatar
19 votes
4 answers
15k views

Is there anyway to make blender print errors in the UI?

For some reason, sometimes error messages encountered while scripting are not printed in the info panel, only the message ...
user avatar
  • 152k

1
2 3 4 5
218