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
41
votes
2answers
36k 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 ...
43
votes
1answer
29k 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!
40
votes
3answers
23k 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?
58
votes
7answers
41k 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 ...
70
votes
8answers
73k 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 ...
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 ...
16
votes
1answer
8k 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 ...
25
votes
1answer
6k views

Control a property with no socket (color ramp swatch, etc) from a Group Node input?

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 ...
31
votes
1answer
31k 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?
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. ...
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, ...
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 ...
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] ...
11
votes
1answer
7k 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 ...
7
votes
2answers
2k 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-...
6
votes
2answers
1k 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 ...
22
votes
4answers
17k 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 ...
10
votes
1answer
6k 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 ...
20
votes
6answers
27k 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 ...
14
votes
3answers
10k 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 ...
14
votes
4answers
20k 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 ...
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 ...
23
votes
1answer
20k 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 ...
10
votes
2answers
15k views

Convert Materials from Cycles to Blender Internal Render

I want to use Freestyle for a scene with lots of different Cycles Materials, is there an easy way to change them all at once to Blender Internal? It would be nice if the materials are somehow ...
5
votes
2answers
5k views

How to add modifiers using python script and set parameters?

I've found some code that could add a modifier but none can set parameters like Octree.
37
votes
7answers
28k 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 ...
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"...
19
votes
4answers
18k 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 ...
5
votes
2answers
5k views

Csv Import pointcloud into Blender

I have 24 points which correspond to 12 different "elements" (2 points per element) saved in an .csv file with the following column order (1: Element Name, 2: x, 3: y, 4: z). I would like to import ...
8
votes
3answers
5k views

Tracing a monochrome image into a 3D, extruded object with a script

Say I want to automate making extruded-text or a 3d logo from an image. An answer that uses extruding a monochrome image of the ubuntu logo to an arbitrary number of units with a python script ...
2
votes
1answer
468 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 (...
9
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
511 views

Handler frame_change_pre doesn't work in render

this works in viewport but not in render. ...
0
votes
1answer
192 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?
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?
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 ...
11
votes
1answer
2k views

Auto save images along with .blend

Blender has a very irritating quirk in which it fails to save an image that you have painted on, when the .blend is saved. To fix this you have to remember to use "save as image", before you save the ....
4
votes
2answers
2k 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 ...
2
votes
1answer
199 views

Trying to make a menu using multiple modules

It's not giving any erros when installing it, also tested the operators before and and they were working fin but i can't make the menu show up. I was trying to call it using "DC_MT_macro_menu&...
15
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: ...
15
votes
1answer
9k views

How to check if two meshes intersect in python?

I need to check if two meshes intersect or not. At the moment I have some python code to find intersections of world axes aligned bounding boxes, next step would be to implement check for mesh ...
8
votes
2answers
4k views

How do I override context for bpy.ops.mesh.loopcut?

I am trying to use loopcut in a python script in Blender 2.71. I have tried using the following code from "Loop cut and slide using python script in blender": ...
10
votes
2answers
14k views

Import 3D XML in Blender or convert it with another tool

I would like to find a way to import 3D XML (zipped file with XML Data and textures) files into Blender or find a workaround without using 3dvia, or AutoDesk to convert it. I know there is a python ...
8
votes
6answers
2k views

How to create a Tetrix/Sierpinski Tetrahedron fractal radiating from 0,0,0 ? Python or nodes

Animation nodes method true to description has been provided by @lemon, Vote his answer UP UP UP! INFERIOR INFERIOR INFERIOR / different concept Mesh. I want to create it not by dissection of ...
7
votes
1answer
2k views

How do you remove a draw handler after it's been added?

I'm making an attempt to use batFINGER's method from this answer for drawing some text on screen without a modal operator, but I'm finding I can't get the text to go away once it's been drawn. ...
2
votes
1answer
495 views

Context is incorrect when calling from a timer

Eevee in Blender 2.8 is so awesome that just saving the viewport (view > Viewport Render Image) looks really good. I'd like to save the viewport periodically from a timer script using the operation ...
23
votes
2answers
38k 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 ...
28
votes
3answers
16k 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....
9
votes
2answers
4k views

Coordinates of corners of camera view border

How to get coordinates of corners of camera border in camera view relative to the viewport area? After checking ...
6
votes
2answers
3k views

How to make a curve path from scratch given a list of (x, y, z) points?

I want to move a soft body object in my scene on a path (curve path). For the path, I want to make it myself from scratch. I basically have a Python List containing (x, y, z) points and want to create ...

1
2 3 4 5
21