Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

72
votes
3answers
37k 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 ...
57
votes
5answers
17k 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) ...
48
votes
3answers
31k 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 ...
41
votes
7answers
24k 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 ...
40
votes
4answers
17k 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. ...
39
votes
6answers
43k 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 ...
32
votes
1answer
17k 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!
32
votes
1answer
1k 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 ...
31
votes
2answers
15k 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 ...
26
votes
3answers
15k views

Control Cycles material nodes and material properties in Python

How can I define the different properties of an cycles material? Such things as glossy, glass, diffuse, rgb-color, emissive via python scripting?
26
votes
3answers
10k 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 ...
24
votes
4answers
27k 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 ...
24
votes
4answers
11k 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 ...
24
votes
1answer
875 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 ...
23
votes
2answers
7k 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
2answers
13k 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.
21
votes
1answer
6k 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 ...
21
votes
4answers
2k 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 ...
20
votes
2answers
598 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?
19
votes
2answers
26k 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 python scripting. I've found a ...
19
votes
1answer
2k 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 ...
18
votes
11answers
14k 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 ...
18
votes
2answers
13k 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 ...
18
votes
5answers
8k 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 : ...
18
votes
4answers
4k 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 ...
18
votes
1answer
7k 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.
16
votes
1answer
4k 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
2answers
23k 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 ...
16
votes
2answers
7k 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 ...
16
votes
3answers
18k 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 "...
15
votes
1answer
17k 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?
15
votes
3answers
6k 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 ...
15
votes
4answers
9k views

How to make Blender use Python2.x?

When Blender is installed, it creates its own copy of Python 3.x. However, I prefer to code in Python 2.x. This makes it difficult for me to work with newer versions of Blender. I would like to know ...
15
votes
1answer
5k 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, ...
15
votes
3answers
12k 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 ...
15
votes
4answers
10k 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 ...
15
votes
4answers
9k 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 ...
15
votes
2answers
3k views

How can I navigate the viewport using Python?

Normally, with most actions that you want to script with Python there is a pop-up tooltip that shows you the function that you want to use. However, for viewport navigation there are no pop-ups, you ...
15
votes
1answer
2k views

How do you calculate square root with nodes?

I'm creating my own merge functions in the compositor, but I've run into a bit of a wall. How do you calculate the square root with nodes? Would one have to write a python node to do this? If so, what ...
15
votes
1answer
10k views

How to read vertices of quad faces using Python API?

Preferable in object mode. I have a mesh I know is made of quads only. I want my script to iterate through each quad and do something with the coordinates of each of the four vertices. I have read ...
15
votes
1answer
2k 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 ...
15
votes
2answers
424 views

Select individual hairs with Python

Is it possible to select specific particle hairs or hair keys in Blender with Python? I'm writing a script on Blender 2.73a which involves finding hairs in a system by their index and applying the ...
14
votes
3answers
6k views

Quick way to get current opened filename in a script?

I'm looking for an efficient way to get the current .blend file name, in a python script. I know how to get its path, with ...
14
votes
1answer
2k views

How could I place objects (buildings) on a flat surface in the BGE?

I'm working on an RTS in BGE, and I am not sure how I could make it so you can place buildings on flat surfaces (or unless there is an easier way). I would love to know how to place buildings when you ...
14
votes
4answers
3k views

Workflow for developing add-on/script

I'm trying to figure out a good workflow for developing scripts and add-ons in Blender. Here's what I'm currently doing as I try my luck with a PyNode add-on: Open blender Create a text editor panel ...
14
votes
4answers
7k 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 ...
14
votes
2answers
10k views

How to get keyframe data from python?

I am looking for help on how to export armatures and their animations in a custom export script. I wish to have an animation format similar to BVH, i.e. a bunch of ...
14
votes
5answers
7k 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] ...
14
votes
1answer
12k views

Selecting and removing particular objects

I have a script that takes in positional data and creates a cube based on their positions. Each time I run the script, I've noticed that the old cubes are still showing up in the User Perspective. It'...
14
votes
3answers
5k 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.