Reader small image

You're reading from  Python Scripting in Blender

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803234229
Edition1st Edition
Right arrow
Author (1)
Paolo Acampora
Paolo Acampora
author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora

Right arrow

Adding operators

Operators can be grouped into different files according to their purpose. For example, transform-related operators such as Elevate Objects, which we covered in Chapter 4, can be put into a file named ops_transform.py, while our first few operators, Create Type Collections, written in Chapter 3, can be put in an ops_collections.py file. All those classes would be then registered by __init__.py and, if needed, added to the add-on interface via relative import.

Another solution is creating one module for all the operators, which can be named operators.py. In this section, we will create an operators module for our add-on.

Writing the operators module

In the structured _addon folder, we will create the operators.py module. It will contain our operator class: we will reuse the Add Random Location operator from Chapter 5. Besides bpy, which is ubiquitous in Blender script, we will import the random module and use randint in the add_random_location function:

import...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023Publisher: PacktISBN-13: 9781803234229

Author (1)

author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora