175
votes
Accepted
How to create a custom UI?
Designing an UI or Add-on is basically a combination of supplying Properties and the inheritance of built-in Type classes (Panel, Operator, Menu etc.).
Properties
Start by defining your Properties ...
63
votes
Accepted
Selecting an object via scripting?
bpy.data.objects['Sphere.017']
refers to an object. (Lets assume all names in quotes are the names of objects in your Blender Scene)
2.8 Recent Version of the API
<...
59
votes
Accepted
Blender 2.8 API, python, set active object
Use the view_layer
Set ViewLayer.active to any object in view layer or None
context.view_layer.objects.active = ob
Note ...
52
votes
How to install Pip for Blender's bundled Python?
First of all, pip is not part of Python so it doesn't come by default with Blender.
It has to be installed for Blender's bundled Python even if you already have pip for some other version of Python on ...
48
votes
Using 3rd party Python modules
While blender's python doesn't come with pip installed, it does have ensurepip. That means that you can do something like this:
...
44
votes
Accepted
TypeError: Element-wise multiplication: not supported between 'Matrix' and 'Vector'
Blender 2.8+ Matrix multiplication
The question code method was in place for Blender <=2.79.9. Blender has since adjusted its mathutils module, replacing the ...
42
votes
Accepted
How to add empty object not using bpy.ops?
This is possible by placing None as the object data:
...
41
votes
Accepted
How to call a confirmation dialog box?
When calling an operator via bpy.ops.* without any execution context the execute() method of the respective operator runs by ...
33
votes
Accepted
Control a property with no socket (color ramp swatch, etc) from a Group Node input?
As far as I know, I don't think it is possible to drive a Color Ramp or Mapping nodes from another socket (but I am not super experienced in drivers). However I have managed to re-create the color ...
33
votes
Duplicating a mesh object
The operator bpy.ops.object.duplicate() will duplicate the selected objects and then make the new duplicate objects selected while de-selecting the original objects....
32
votes
Accepted
Techniques for modeling a network of blood vessels
This is a nice case of how node based geometry generation can create crazy stuff. First off, you'll never guess who this is in the following Blend file:
You will need the latest iteration of ...
32
votes
Accepted
Finding vertices in a Vertex Group using Blender's Python API
Methods
1. List comprehension
As mentioned by Pycoder in the comments below, using operators is often slow. So a quicker and simpler (and X2 faster) method to get all the verts that belong to a ...
Community wiki
30
votes
Accepted
How to use Keyframes and the Python API programmatically?
Figured it out!
Here's how to use the Python API to set it:
...
28
votes
Accepted
How to put together a driver with python
This is a general function I use in many of my scripts for adding drivers. You're welcome to implement it in your own script. It's pretty general and supports inverse relationships between properties (...
26
votes
Accepted
How do you get an object's position and rotation through script?
You can access an object's transformations through the relevant properties (location, rotation_euler - for Euler XYZ rotations, and scale) this way:
...
23
votes
Add Nodes to Material with Python
The answer provided is only partially helpful. Or it is outdated in 2.7
Yes you have to add the nodes (use_nodes = True). However the default material is the ...
23
votes
Accepted
Add modifier to selected and another to active object
I'd suggest not using modifier add operator and use modifiers.new(name, type) instead. Avoids hassle of changing the active object and also if using the op to add ...
23
votes
Accepted
Converting code to work in blender with sliders
Fragment Shader Solution
If we multiply the normalized polar angle by some number representing the number of strips and take its modulo with 1, it will give us a number of sub-normalized polar angle ...
22
votes
Where does console output go
Here is my script which redirects the print() function to all open python console windows.
import bpy
def print(data):
for window in bpy.context.window_manager.windows:
screen = window....
22
votes
Accepted
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?
Yes! This is possible.
I finally managed to get it to work in a loop.
The current solution allows to cancel the operation with the X button in the Info Window and the ESC key. The images are rendered ...
21
votes
Accepted
Adding Named Objects in Blender with Python API
When you use bpy.ops.object.add() the newly created object becomes the active object, so right after creating the object you can alter it's name with
...
21
votes
Accepted
How to automatically fit the camera to objects in the view?
There is an operator to do exactly this. it can be called from Python or accessed from a menu.
Select the objects you wish to put in the camera view.
View -> Align View -> Align Active Camera ...
20
votes
Selecting an object via scripting?
I'm just doing my duty here. Quick answer that works in 2.8:
...
19
votes
Techniques for modeling a network of blood vessels
I once created a blender addon as a part of my bachelor thesis about neuronal structures, which computes spanning trees using particle systems. You could use this to generate 3-dimensional tree ...
19
votes
Accepted
18
votes
How to remotely run a Python script in an existing Blender instance?
This can be done with sockets,
using the following examples you can run from the command line:
From the first terminal:
blender --python blender_server.py
...
18
votes
18
votes
How to open system console to get output from Blender on Mac OS 10?
Right click on the Blender icon in the Applications folder and select "Show Package contents". Make an alias of Contents/MacOS/Blender by right clicking and ...
18
votes
2D solidify. Is it possible?
The easy way, which requires a bit (just a bit) of manual work:
Install "Edit Tools 2" and "Loop Tools" addons. They're both
available in basic blender 2.79/2.79a, so just find them in addons
and ...
17
votes
Accepted
How to create submenus with dynamic content?
You can make each submenu have its own context by setting a variable in the UILayout.
The script can be made to work as expected with only minor changes.
Define a ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scripting × 6252python × 4660
add-on × 650
mesh × 326
animation × 322
interface × 321
rendering × 243
objects × 243
game-engine × 199
materials × 192
node-editor × 186
operator × 185
properties × 175
modeling × 161
modifiers × 161
transforms × 144
export × 140
import × 130
bmesh × 127
drivers × 120
3d-view × 115
uv × 106
armature × 102
camera × 101
command-line × 101