The Python API opens up Blender to technical users and add-on developers, allowing the creation of custom tools and workflows. Blender 2.80: Addon API Version Info. To prevent collisions 2.8x enforces naming conventions (already in use across much of Blender's code-base) for class names. Blender is a powerful software and open source 3D creation suite. Advanced users employ Blender’s API for Python scripting to customize the application and write specialized tools; often these are. Mock for 'cubeadd' Blender API 8Observer8. A Detailed, Artist-friendly guide to understanding and using Blender’s Python API to create your own Addons and Tools.
File Selection With Python
I write this because I couldn’t easily find a way to create a window in Blender where I can select a file and then use that file. This creates an easy way to open a file, and it works out of the box; copy and paste the code into Blender and run it. As a side note, after searching for quite a while, this code was found on the Blender documentation, tucked away in its far corners.
An Explanation of The Code
This code is very minimal, and could be condensed even more. What it will do is bring up a file selection window. You are then able to browse though folders and select a file and then you can press the button once you get the file you want.
This script doesn’t actually do anything with that file, but what ever you want the script to do with have to be coded in the execute()
function.
There are three variables set up that are later referenced in the draw()
function. These variables help create the menu on the side of the window. With this, you can create options for the user to provide and affect what the script does with the file.
The draw()
function places these objects on rows and columns. Every time you use the col.prop()
function, the next time you use it, that value will be placed on the next column. (actually, these names are backwards) and every time you use the row.prop()
it will add another variable to that same row.
To access the filename to actually open the file with python, it would be, in this example, self.filename
, and likewise, to access the other variables, you would use self.my_float
Well that is about it for basics on creating a file selector with Blender 2.59
To set mesh (object) as active in Blender 2.8 Python API the “context.view_layer” is used instead of “context.scene”.
When trying to make object active with “bpy.context.scene.objects.active” Blender throws an error:
AttributeError: bpy_prop_collection: attribute “active” not found
To make object active in Blender 2.8 use the following code:
Blender Apic
Blender Api Python
2 | bpy.context.view_layer.objects.active=obj# 'obj' is the active object now |