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).

Blender can be scripted using Python. In the past, there have been unofficial projects to bring other languages to Blender, but these are not supported and should not be brought up here.

Almost any aspect of Blender can be scripted through its extensive and powerful Python API. Questions (NB: Not tutorial requests) regarding scripting in Python are supported here.

However, scripting Blender (for headless rendering, for instance) using a shell such as sh, bash or powershell (on Windows) may be supported depending on the situation; so long as the question is relatable directly to a Blender issue.

For example:

On topic:
"What arguments should I use to make Blender render 3 images from the command line?" - in which the shell in question is sh and an example script is provided.

Off topic:
"Why is my Blender cmd rendering script not working?" - in which the shell is sh and the problem is with the script (not Blender).

Questions regarding scripting in other languages, in which the problem is with the script or language in question, are better served on other sites across the Stack Exchange network, such as Superuser, Unix and Linux, and Ask Ubuntu.

See: What questions should be definitely off-topic?

6371 questions
20
votes
2 answers

Get Blender X,Y,Z and Bounding Box with script

I need to get the x,y,z values of an object as well as the bounding box through a script. So far I have the area and volume with the following code: bm = bmesh.new() bm.from_object(bpy.context.object, bpy.context.scene) area = str(sum(f.calc_area()…
Alex Husarenko
  • 545
  • 2
  • 4
  • 10
19
votes
2 answers

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 create a tetraeder. First I create the mesh, then…
Zéiksz
  • 1,959
  • 5
  • 23
  • 32
13
votes
1 answer

How to prevent malicious code execution loading blend files?

Since I download from time to time example files from blogs, wikis etc. I would like to know how I can avoid execution of malicious code. Is it enough to disable the autoexec switch and see what is in the text editor?
stacker
  • 38,549
  • 31
  • 141
  • 243
10
votes
1 answer

Can I perform an action when a file is saved or loaded?

If I create a Blender file with a single plane that has 10 000 particles of hair, the resulting file size is 9.9 MB. If, before saving, I reduce the "Number" (RNA ParticleSettings.count) to 1, the resulting file size is only 435 KB. Because the hair…
wchargin
  • 9,452
  • 5
  • 41
  • 66
10
votes
1 answer

Creating own editor type

Is it possible to create your own editor type with python? I know that I can edit the sources of existing ones like the INFO header. But I want to create a complete new one where I can place my operators.
Miguellissimo
  • 1,355
  • 2
  • 16
  • 29
10
votes
3 answers

What's the difference among object, active_object, and selected_objects?

I am wondering if following statements are true: active_object is always identical to object. active_object(or object if previous statement is true) is always the first one of selected_objects. (This seems to be a false statement since if I use…
TheBusyTypist
  • 415
  • 3
  • 12
9
votes
1 answer

How to import PyQt into Blender?

I have been trying to import PyQt into Blender following Has anyone hooked up PySide to Blender? in Windows. However I am unable to get it to work. import sys sys.path.append('C:/Users/apple/blenderqt/py/Lib/site-packages') import bpy from…
user2888499
  • 181
  • 3
  • 13
8
votes
1 answer

Will vertex indices change?

If I base a script on vertex indices -- how much risk that the index will change with time? Is it possible to assign some identifier of my own to a vertex? For example, add a uuid for every vertex I am interested in.
dimus
  • 3,292
  • 9
  • 32
  • 43
8
votes
1 answer

How do I get the bounding box of all objects in a scene

I have a scene with objects organized hierarchically like this: I would like to get the overall bounding box of the 00000_361.L3B EMPTY object - however, since this is an empty it has no dimensions, and its bounding box also has no dimensions. I…
simone
  • 745
  • 4
  • 14
8
votes
3 answers

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 taking only the number of units and the monochrome…
RobotHumans
  • 1,047
  • 1
  • 11
  • 15
7
votes
2 answers

Displaying vertex indices in Blender 2.8 using debug mode

I'm trying to enable debug mode in blender 2.8 in order to see vertex indices in edit mode and from the instructions I'm following I'm supposed to execute bpy.app.debug = True but I still cannot see the indices. How do I do this in blender 2.8?
Espen Sales
  • 1,182
  • 4
  • 16
  • 33
6
votes
0 answers

Add custom textures and vertex attributes

I'm a new user of Blender, but I have 10 years experience of 3d development (mainly C++/OpenGL, but I know Python pretty well). Now I plan to use Blender as a replacement tool for the "good old ones we made by hand" in my company. These tools are…
Orel
  • 61
  • 1
5
votes
1 answer

How to leave trails

Is there a way to make Blender leave trails or, in other words, not clear the canvas (I know "canvas" isn't Blender jargon). In Three.js, there is an option to "Preserve drawing buffer" which basically makes the library never erase the canvas. Ex:…
Jared Beach
  • 151
  • 2
5
votes
1 answer

Can't Add Platonic Solids in Blender via Script

After watching the following tutorial, I thought I was going to customize it a bit and add a dodecahedron in the place of the ico sphere. Tutorial that I followed https://www.youtube.com/watch?v=F-cgCXg7Z3o As mentioned in the tutorial, I found out…
Rob Sawyer
  • 151
  • 1
5
votes
1 answer

`ValueError: 1-2 args execution context is supported` on call to `bpy.ops.outliner.show_hierarchy` in Blender 4.0.1

I have the following code which I use for expanding all collections in the outliner def toggle_collection_collapse(state): area = next(a for a in bpy.context.screen.areas if a.type == 'OUTLINER') bpy.ops.outliner.show_hierarchy({'area':…
1
2 3
22 23