blendersynth.blender.utils

Context managers and operations for handling Blender

class blendersynth.blender.utils.CursorAt(target)[source]

Context manager for moving the cursor to a specific location in space. On exit, will return the cursor to its original location.

__init__(target)[source]

Initialize with the target location

Parameters:

target (Union[Vector, ndarray, List, Tuple]) – Location to move the cursor to

class blendersynth.blender.utils.GetNewObject(scene)[source]

Context manager for getting the newly imported object(s) to the scene.

On exit, will return the newly imported object(s).

Assumes that either (1) only one object is imported, or (2) there is a hierarchy to the imported objects, and the top level object is the one to return.

__init__(scene)[source]
class blendersynth.blender.utils.SelectObjects(objects=(), active_object=None)[source]

Context manager for selecting objects. On exit, will reselect the objects that were selected before entering the context.

__init__(objects=(), active_object=None)[source]

Initialize with a list of objects to select

Parameters:
  • objects (List[Object]) – list of bpy.types.Object

  • active_object (Object) – [Optional] The active object to set

class blendersynth.blender.utils.SetMode(target_mode, object=None)[source]

Context manager for changing the mode of a specific object in Blender (e.g., to POSE), returning to the original mode on exit.

__init__(target_mode, object=None)[source]

Initialize with the target mode and object

Parameters:
  • target_mode (str) – Mode to set the object to

  • object (Object) – bpy.types.Object to set the mode of

blendersynth.blender.utils.animatable_property(data_path, id_path='')[source]

Decorator that wraps around a function to take a frame number and value, and set the property at that frame.

Example usage:

@animatable('location')
def set_location(self, value):
        self._location = value

If you want to set the property at the current frame, use the setter as normal:

obj.set_location((1, 2, 3))

To set the property at a specific frame, simply add the frame keyword:

obj.set_location((1, 2, 3), frame=10)

Which is functionally equivalent to:

obj.set_location((1, 2, 3))
obj.object.keyframe_insert(data_path='location', frame=10)
Parameters:
  • data_path (str) – the data path of the property to set

  • id_path (str) – Use for animating ID blocks other than object (e.g. ‘data’)

Return type:

callable

blendersynth.blender.utils.get_node_by_name(node_tree, key, raise_error=False)[source]

Given a nodetree and a key, return the first node found with label matching key.

Parameters:
  • node_tree (NodeTree) – Node tree to search

  • key (str) – Key to search for

  • raise_error (bool) – If True, raise KeyError if key not found

Return type:

Node

Returns:

Node with matching label

blendersynth.blender.utils.handle_vec(vec, expected_length=3)[source]

Check vec is expected_length. Convert from tuple or ndarray to mathutils.Vector.

Parameters:
  • vec (Union[Vector, ndarray, List, Tuple]) – Vector to check

  • expected_length (int) – Expected length of vector

Return type:

Vector