Questions tagged [scripting]

Questions concerning scripting in Blender using the Python programming language. Also use this tag for questions about scripting in OSL (Open Shading Language).

Filter by
Sorted by
Tagged with
68
votes
8answers
70k 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 ...
56
votes
7answers
39k 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 ...
42
votes
1answer
28k 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!
42
votes
1answer
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 ...
38
votes
2answers
33k 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 ...
38
votes
3answers
22k 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?
36
votes
3answers
52k 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 ...
35
votes
5answers
25k 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 ...
33
votes
2answers
18k 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 ...
32
votes
2answers
3k views

Techniques for modeling a network of blood vessels

If you've ever seen anything like Body Worlds or the Bodies: The Exhibition you'll know how they dissect individual organ systems and put them on display with a technique known as plastination. For ...
31
votes
1answer
29k 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?
28
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 ...
27
votes
3answers
15k views

Show mesh vertices ID

I am try to do something based on the ID of a vertices. I want blender to show me the vertices ID. How can I have blender show me the ID in the viewport? I do not see an option in the Mesh Display tab....
26
votes
2answers
10k 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 ...
25
votes
1answer
6k views

Possible to control a Driver from a Group Node input slider?

Sometimes I create Material Groups to be used as appendable reusable assets. Unfortunately sometimes parameters I want to control using a Group Node's slider are not available for routing to a Group ...
24
votes
1answer
7k views

How to implement custom icons for my script/addon?

Is it possible to use different icons other than the default set and how?
23
votes
1answer
19k 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 ...
23
votes
3answers
11k 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 ...
23
votes
2answers
36k 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 ...
23
votes
2answers
4k 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 ...
22
votes
4answers
16k views

How are vertex indices determined?

How does the program decide what indices to assign to vertices? If you create a primitive, are the indices generated randomly, or by some base primitive setting? If you extrude new vertices, will they ...
21
votes
3answers
13k views

Blender rendering automation (build script)

I would like to automate the proccess of rendering images (sprites). What I want to do is to render an image of the same model with different textures, ideally the texture filename would be passed as ...
20
votes
6answers
26k 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 ...
20
votes
5answers
16k 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 ...
19
votes
4answers
12k 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 ...
19
votes
5answers
11k 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] ...
19
votes
3answers
32k 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 "...
18
votes
4answers
17k 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 ...
18
votes
8answers
8k views

How to stop Blender from making the CPU overheat?

Apparently my CPU or GPU overheats when Blender renders more than a few minutes. The computer suddenly powers down, taking down all running apps, email I'm writing, etc. This is almost never a ...
18
votes
2answers
13k views

How to create a mesh programmatically, without bmesh?

I do not want to use BMesh this time. I want to create a mesh programmatically, for this purpose I created this short script to see what I do wrong in my importer script. In this script I try to ...
18
votes
2answers
14k views

how to use BMesh to add verts, faces, and edges to existing geometry

I've puzzled about this for a while, but haven't found an answer I understood. This snippet below does add geometry (3 verts and a face) but it also generates an error, Does going to object mode make ...
18
votes
3answers
582 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 ...
16
votes
3answers
14k 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
4answers
4k 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 ...
16
votes
1answer
7k 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 ...
16
votes
1answer
7k views

How to add empty object not using bpy.ops?

How to add an empty object with python using bpy and not using any ops? My code so far is doing this: ...
16
votes
1answer
11k 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 ...
16
votes
1answer
3k views

What do new bpy class naming conventions in Blender 2.80 actually mean?

What are the new class naming conventions in Blender's 2.80 Python API for add-ons? It says here: This constraint applies to the bl_idname of each class (or the ...
15
votes
3answers
10k 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 ...
15
votes
4answers
4k views

Is it possible to run a script from an external editor without reloading the file?

I use an external to Blender text editor (vim). I understand I can write in it and then reload file in Blender's text editor. Is there a way to run a script from external editor without this ...
15
votes
1answer
5k 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"...
15
votes
3answers
8k 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, ...
15
votes
2answers
4k 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
2answers
2k views

Adding operator to the toolshelf?

I'm just starting to learn scripting in Blender with Python. I made a simple operator following the quickstart intro on the Blender documentation: ...
15
votes
3answers
12k 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 ...
15
votes
2answers
6k views

How to unlink material from a mesh, with python script?

Blender 2.68a, Python 3.3 I would like to unlink material from a mesh, and even after googling a hour I don't know how to do it. I only saw scripts that work in Blender 2.5x only for this. So could ...
15
votes
3answers
1k views

Add a custom curve mapping property for an add-on?

Question The title says it all. I want to be able to make this in Blender's UI, and sample it at specific points from an add-on: Problem There is very insufficient documentation on this, and I can't ...
14
votes
4answers
19k 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 ...
14
votes
4answers
6k 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: ...
14
votes
3answers
9k 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 ...

1
2 3 4 5
95