Skip to main content

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
52 votes
2 answers
48k 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!
Jonathan's user avatar
  • 621
57 votes
2 answers
60k 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 ...
DragonautX's user avatar
  • 1,316
47 votes
3 answers
28k views

Control Cycles/Eevee material nodes and material properties using python?

How can I define the different properties of an Cycles/Eevee material? Such things as glossy, glass, diffuse, RGB-color, emissive via python scripting?
binaryBigInt's user avatar
  • 1,047
70 votes
10 answers
59k 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 ...
Gouwi's user avatar
  • 701
99 votes
10 answers
128k 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 ...
P i's user avatar
  • 3,951
34 votes
4 answers
6k 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 ...
Zéiksz's user avatar
  • 1,979
11 votes
3 answers
4k 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 ...
Somebody285's user avatar
41 votes
1 answer
51k 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?
binaryBigInt's user avatar
  • 1,047
17 votes
1 answer
4k 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. ...
Polosson's user avatar
  • 6,584
15 votes
1 answer
11k views

How to create a Folder/File 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 ...
doomslug's user avatar
  • 1,819
25 votes
1 answer
15k 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 ...
batFINGER's user avatar
  • 84.5k
14 votes
2 answers
4k 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-...
Chaos's user avatar
  • 622
14 votes
2 answers
2k views

A comprehensive list of operator overrides

I feel like I'm always spending far too much time playing scripting whack-a-mole whenever I want to override an operator in one of my scripts. I'd like to build a comprehensive one-stop-shop list for ...
Gorgious's user avatar
  • 31.5k
28 votes
1 answer
8k 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 ...
Mentalist's user avatar
  • 19.3k
46 votes
11 answers
58k 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 ...
ideasman42's user avatar
  • 47.6k
13 votes
1 answer
12k 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 ...
Tak's user avatar
  • 6,303
31 votes
2 answers
14k 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 ...
MrFlamey's user avatar
  • 3,869
22 votes
6 answers
36k 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 ...
P i's user avatar
  • 3,951
16 votes
3 answers
14k 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, ...
Roman Volodin's user avatar
27 votes
4 answers
26k 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 ...
Ascalon's user avatar
  • 6,629
22 votes
5 answers
33k 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 ...
Zéiksz's user avatar
  • 1,979
21 votes
6 answers
16k 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] ...
Hatoru Hansou's user avatar
17 votes
3 answers
14k 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 ...
Batwam's user avatar
  • 325
7 votes
1 answer
2k 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?
BlenderUser123's user avatar
6 votes
2 answers
12k 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.
Claire's user avatar
  • 95
28 votes
1 answer
31k 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 ...
Georges D's user avatar
  • 5,022
9 votes
2 answers
4k views

Limit "prop_search" to Specific Types of Objects

Currently working on a piece of custom UI that contains an object selection box. layout.prop_search(scene, "myselection", scene, "objects") I'm wondering how I ...
BlenderBro's user avatar
  • 1,201
30 votes
1 answer
11k views

How to implement custom icons for my script/addon?

Is it possible to use different icons other than the default set and how?
Jaroslav Jerryno Novotny's user avatar
20 votes
1 answer
10k 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"...
Jabberwock's user avatar
19 votes
2 answers
15k 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 ...
Zéiksz's user avatar
  • 1,979
5 votes
2 answers
3k views

Start script on open blender file

I have written up a script for my model. But there is a bit of a problem with it. As in I have to run the script every time I open the file. I want the script to run automatically when I open the ...
Raspberry's user avatar
  • 425
11 votes
2 answers
7k 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": ...
Mike N.'s user avatar
  • 350
30 votes
2 answers
63k 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 ...
B Newmark's user avatar
  • 1,240
19 votes
4 answers
10k 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: ...
Ray Mairlot's user avatar
  • 29.3k
8 votes
3 answers
7k 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 ...
RobotHumans's user avatar
  • 1,047
5 votes
1 answer
2k 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&...
Udjani's user avatar
  • 117
10 votes
2 answers
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 ...
user2567875's user avatar
10 votes
1 answer
4k 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 ...
sambler's user avatar
  • 55.5k
8 votes
1 answer
4k 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. ...
andyV's user avatar
  • 623
5 votes
2 answers
4k 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 ...
doomslug's user avatar
  • 1,819
4 votes
2 answers
2k views

Handler frame_change_pre doesn't work in render

this works in viewport but not in render. ...
user3202179's user avatar
2 votes
1 answer
2k 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 (...
Terela02's user avatar
24 votes
4 answers
28k 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 ...
rioforce's user avatar
  • 2,052
19 votes
2 answers
18k 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 ...
zeffii's user avatar
  • 39.7k
17 votes
4 answers
5k 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 ...
ajwood's user avatar
  • 10.1k
16 votes
3 answers
41k views

How do you get an object's position and rotation through script?

I'm working on a project that requires me to get some of the position and rotation values to give to an Arduino via pyserial, but after sifting through the Blender documentation I can't find how to ...
Carrot M's user avatar
  • 163
13 votes
4 answers
5k 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 ...
BlenderBro's user avatar
  • 1,201
13 votes
1 answer
3k 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 ....
GiantCowFilms's user avatar
12 votes
1 answer
2k views

How to get one UIList to control the contents of another UIList?

I have two dynamic lists. One is for strings and another one for objects. When the string changes I need the other list to show the objects assigned to the string in the first list. So I would need ...
tintwotin's user avatar
  • 2,436
11 votes
4 answers
4k views

How can I sort vertex positions sequentially indices in a closed area?

I need to sort the vertices sequentially to make an effect, something like this video. I know I should draw them by hand, but sometimes when I subdivide edges, vertex indexes will change. The vertices ...
Seyed Morteza Kamali's user avatar

1
2 3 4 5
27