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.

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!
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 ...
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 ...
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?
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 ...
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 ...
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. ...
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, ...
5
votes
1answer
4k 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 ...
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 ...
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?
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 ...
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 ...
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] ...
12
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. ...
8
votes
1answer
3k views

Auto-run scripts security options

We have a preferences option to enable auto-run of python scripts when opening blend files. We can also add paths that are excluded from auto-running scripts. Then we have a cli options to enable or ...
3
votes
1answer
4k 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 ...
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 ...
8
votes
2answers
4k views

Object selection box in addon

In my addon panel, how can I have an object selection box? And what data type would I use to store the the selected object? It should look like this:
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.
12
votes
1answer
3k views

Bake Fluid Simulation via CLI or Python?

I would like to run a fluid simulation on a headless Ubuntu machine I have lying around. I did manage to find a bug report on the issue but to no avail. Has anyone else had any success? Or perhaps a ...
6
votes
4answers
2k views

How do I make a weapon shoot at the center of the screen?

I've been researching this for weeks and only found bad results. I think its time for a good answer. I have a rocket launcher, so I can't "fake" the bullet. There is no way to fake a rocket. I need it ...
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.
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 ...
13
votes
5answers
17k 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 ...
13
votes
1answer
5k 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, ...
11
votes
3answers
8k views

How can I get the camera's projection matrix?

As asked. I need a way to get the projection matrix of the active camera, via python. EDIT: I think this question is different from the one asked here, because getting a matrix is different from ...
3
votes
2answers
2k views

How can i add a text help window and a help button into the 3D View?

I have seen in a video form cgcookies that they added a Help button and a Help text box right into the 3D View. How can this be achieved within an Addon?
7
votes
1answer
5k 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 ...
4
votes
2answers
887 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-...
3
votes
2answers
1k views

Object creation slows over time [duplicate]

I know that this has been asked before, but the answers that others have received did not help me much. When creating objects through Python, using bpy.ops.mesh.primitive_cube_add() there is an ...
10
votes
2answers
6k 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 ...
7
votes
2answers
5k 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 ...
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 ...
11
votes
3answers
6k 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 ...
11
votes
4answers
12k 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 ...
8
votes
1answer
3k views

How to handle creating a node group in a script?

I am attempting to make a python script that creates a nodegroup based on some scene properties, however the group_make operator needs to be in a node editor ...
13
votes
6answers
10k views

Python - Set material to material slot

I am using the Blender Internal render engine. I have an material slot with no material assigned to it. How can I assign a material to a slot using python? This should work in edit mode as well. ...
9
votes
1answer
2k 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"...
6
votes
3answers
9k views

How to view python error messages? [duplicate]

I'm following a tutorial and I can´t go forward and finish the tutorial. My problem is that when i click on run script it gives me a problem saying "Python script fail, look in the console for now..." ...
2
votes
1answer
1k views

Generate video sequencer project from a script

I have a number of different MP4 files. I want to create a Blender project file that has these files in a set order and each video stream starting at a set start time. I know the files, I know the ...
6
votes
1answer
570 views

Possible to create new Application Handler?

Blender's application handlers are listed here, but is it possible to create a new one? For example, I'd like an application handler which is a callback for every time I add a strip to the Video ...
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 ...
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?
11
votes
3answers
18k 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 ...
9
votes
1answer
3k views

Why is accessing image data so slow?

This script in the Python console: ...
8
votes
1answer
5k views

How to create a Folder 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 ...
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 ...
6
votes
1answer
975 views

Execute a python function whenever the user interacts with the program

Is it possible to execute a function every time the user does something? I want the function to check what the last user interaction was and then, if the interaction was to rename something, to give ...
4
votes
3answers
4k views

How to find number of animated frames in a scene via python?

I need to find the number of animated frames after importing a bvh file in blender. scene.frame_start and ...