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.

Filter by
Sorted by
Tagged with
98 votes
10 answers
125k 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,921
92 votes
4 answers
88k 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 ...
BenjaminGolder's user avatar
83 votes
3 answers
56k views

How can I quickly generate / create a large city without modeling it all by hand?

I am trying to create an urban open-world environment in Blender that would be about one square kilometre in size. To avoid having to model hundred of individual buildings, I am looking for a way to ...
A A's user avatar
  • 933
71 votes
6 answers
25k views

Is there a tool for scientific visualization using Blender?

Is there an interface or API that allows using Blender as a tool for mathematical and scientific visualization? It should allow Blender to read in data (a la gnuplot or matlab, perhaps using scipy) ...
KDN's user avatar
  • 812
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
70 votes
5 answers
40k 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. ...
BenC's user avatar
  • 803
58 votes
5 answers
82k 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 ...
Jan Rüegg's user avatar
56 votes
2 answers
59k 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,306
52 votes
2 answers
47k 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
49 votes
1 answer
3k 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 ...
rraallvv's user avatar
  • 4,551
48 votes
3 answers
99k 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 ...
AaronJPung's user avatar
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
45 votes
11 answers
57k 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.4k
41 votes
1 answer
50k 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
38 votes
2 answers
33k views

How to get the directory of open blend file? (from Python)

What's the best way to get the full directory of the current Blender file in Python? It should be cross-platform.
Garrett's user avatar
  • 6,596
38 votes
2 answers
14k 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 ...
Salvatore's user avatar
  • 757
35 votes
2 answers
24k 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 ...
lucblender's user avatar
  • 3,343
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,959
32 votes
3 answers
21k views

Is the Blender GUI package available for other programs?

I really love the look of Blender's built-in GUI, and would potentially like to use these tools in some of my other Python applications. As I understand it, Blender created all of these tools from ...
Gwen's user avatar
  • 11.6k
31 votes
3 answers
54k views

Python: Selecting object by name in 2.8

The following: bpy.data.objects['Cube'].select = True bpy.context.scene.objects.active = bpy.data.objects['Sphere.017'] don't work in Blender 2.8, they did in 2....
Michael Teiniker's user avatar
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,839
30 votes
9 answers
29k views

Efficient way to get selected vertices via python (without iterating over the entire mesh)

What's the best/fastest way to construct a list of selected vertices for a mesh object in python? I want to avoid iterating over every vertex in the mesh if possible, since that seems like a really ...
Qutorial's user avatar
  • 3,312
30 votes
1 answer
17k 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.
TARDIS Maker's user avatar
  • 5,732
30 votes
2 answers
62k 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
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
29 votes
3 answers
20k 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 ...
stacker's user avatar
  • 38.5k
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
  • 4,982
27 votes
1 answer
14k 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, ...
Hamburml's user avatar
  • 957
27 votes
1 answer
1k views

Closing "Fibonacci's Hole"

Creating a sphere using the points defined by Spherical Fibonacci Mapping. For the most part it is easy to "skin" by using two consecutive fibonacci numbers as steps to loop on the index. And get ...
batFINGER's user avatar
  • 84.3k
26 votes
13 answers
34k views

How can I add a cube?

I am trying to add cubes to my scene. I'm sure there are lots of ways to get a cube into the scene (but for the purposes of this question, I have no idea what they are) - Are there any ways to add a ...
X-27 is done with the network's user avatar
26 votes
8 answers
34k 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 ...
lucblender's user avatar
  • 3,343
26 votes
10 answers
16k views

How to build Blender as a Python module?

I have seen this question now many times and every question here and on other forum points to build blender as python module experimental tutorial by ideaman42. Now sadly a lot of answers are invalid ...
Hakaishin's user avatar
  • 577
26 votes
1 answer
1k views

Property Panel Custom Popup Menu when user presses hotkey over an input field

is it possible to trigger this kind of menu: in the property panel when I press a hotkey over a button/input field? I want to specifically,when the user presses a specific hotkey when over an input ...
Luca Scheller's user avatar
25 votes
1 answer
14k 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.3k
24 votes
4 answers
27k 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,042
24 votes
3 answers
19k views

Pointing the camera in a particular direction programmatically

I'm trying to use Python to place a camera. I know the camera's location, and the forward and up vectors for the camera (i.e. the direction it's pointing and its orientation). How do I do this? I ...
David Given's user avatar
24 votes
2 answers
6k 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 ...
mg007's user avatar
  • 821
23 votes
5 answers
20k views

How to know which object is using a material

How to know which object is using a material. I know that a material is used 4 time -> picture under: I'm searching a solution with python and I'm blocked here : ...
lucblender's user avatar
  • 3,343
23 votes
3 answers
17k 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 ...
Polosson's user avatar
  • 6,554
23 votes
2 answers
1k views

How to make a dynamically expanding menu in Blender?

Say we want to navigate a tree structure without knowing all the data ahead of time, is it possible to do this in Blender? For example, a menu which dynamically loaded a directory hierarchy from the ...
ideasman42's user avatar
  • 47.4k
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,921
22 votes
5 answers
29k views

Importing python modules and text files

I am new to blender, but not python, and have been asked to create a user-input dependent, stylized animation of a protein network I am working with: text document >> information processed by python-...
Henry Ehlers's user avatar
22 votes
6 answers
16k views

Where can I find what version of python is bundled with certain Blender versions?

The question is where I can reliably find the information on which python version is bundled with a certain Blender release (like 2.72b at the moment)? I need to find the major and minor version ...
Mayqel's user avatar
  • 443
22 votes
5 answers
22k 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 ...
dimus's user avatar
  • 3,292
22 votes
2 answers
11k views

Blender sets Compute Device (CUDA) but doesn't use it for actual render (on EC2 GPU Instance)

I'm trying to set up some automated render servers on EC2 using their GPU instance type (g2.2xlarge). I'm running blender in the background with a python script that renders the image I want and saves ...
Ritwik's user avatar
  • 323
21 votes
2 answers
65k views

Set active object with python

I want something along the following lines: ...
clankill3r's user avatar
  • 1,191
21 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,959
21 votes
4 answers
8k views

Convert Curves to Grease Pencil?

I'd like to know if there's a way/add-on to convert curves to Grease Pencil strokes? I know you can convert in the other direction, but I can't find anything to create Grease Pencil strokes from ...
Shawn Altorio's user avatar
21 votes
3 answers
14k 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.
zeffii's user avatar
  • 39.6k
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

1
2 3 4 5
263