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).
972
questions
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 ...
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!
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 ...
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?
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 ...
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
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
...
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, ...
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 ...
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 ...
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?
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] ...
6
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-...
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.
...
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
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 ...
9
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 ...
9
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 ...
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 ...
21
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 ...
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 ...
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 ...
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 ...
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"...
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 ...
7
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 ...
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
419 views
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
...
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 ...
12
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 ....
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.
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 ...
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 ...
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 ...
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
13k 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
1k 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
294 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 (...
2
votes
1answer
448 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
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 ...
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....
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?
14
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 ...
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
...
5
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 ...
8
votes
2answers
7k views
Get center of geometry of an object
With Object > Transform > Origin to Geometry, an object's origin is moved to its geometry's center.
How can I get this center in script?
I don't want to move its origin, I just need to get its center....
10
votes
4answers
2k views
How can I create a mathematically correct arc/circular segment?
Given 3 vertices, or a chord and height, how can I create a mathematically correct arc/circular segment with an even distribution of vertices while controlling for the number of vertices.
I ...
11
votes
2answers
8k views
Add modifier to selected and another to active object
I am trying to set up an operator to use the BoolTool after I set a position and modifier on Selected object and a different one on the Active object. I basically need to move the selected object up ...