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 ...
p2or's user avatar
  • 15.5k
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 <...
atomicbezierslinger's user avatar
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 ...
batFINGER's user avatar
  • 83.5k
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 ...
B Newmark's user avatar
  • 1,240
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: ...
NAS's user avatar
  • 581
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 ...
batFINGER's user avatar
  • 83.5k
42 votes
Accepted

How to add empty object not using bpy.ops?

This is possible by placing None as the object data: ...
TLousky's user avatar
  • 16k
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 ...
p2or's user avatar
  • 15.5k
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 ...
PGmath's user avatar
  • 25k
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....
sambler's user avatar
  • 55.1k
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 ...
aliasguru's user avatar
  • 11.2k
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 ...
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: ...
Julian's user avatar
  • 561
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 (...
TLousky's user avatar
  • 16k
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: ...
TLousky's user avatar
  • 16k
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 ...
fritzvd's user avatar
  • 331
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 ...
batFINGER's user avatar
  • 83.5k
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 ...
Omar Emara's user avatar
  • 22.5k
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....
TheMindVirus's user avatar
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 ...
Chaos's user avatar
  • 612
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 ...
sambler's user avatar
  • 55.1k
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 ...
ideasman42's user avatar
20 votes

Selecting an object via scripting?

I'm just doing my duty here. Quick answer that works in 2.8: ...
user875234's user avatar
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 ...
Parkuhr's user avatar
  • 826
19 votes
Accepted

Clear Custom Split Normals Data on all objects

...
Raffia16th Blaze's user avatar
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 ...
ideasman42's user avatar
18 votes

How to create a custom UI?

Modified version -- for blender 2.80 ...
Daniol Dan's user avatar
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 ...
user007's user avatar
  • 526
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 ...
Alexander Podgayko's user avatar
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 ...
ideasman42's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible