ddg.blender.object module
Collection of utility functions dealing with Blender objects
- ddg.blender.object.blender_data_to_object(name, data)[source]
Wrap a Blender data-block in a Blender object.
- Parameters:
- namestr
The
nameattribute of the object.- databpy.types.ID
A Blender data-block, e.g. curves and meshes whose types -
bpy.types.Meshandbpy.types.Curverespectively - are subclasses ofbpy.types.ID.
- Returns:
- bpy.types.Object
- ddg.blender.object.link(bobj, collection)[source]
Link a Blender object to a collection.
- Parameters:
- bobjbpy.types.Object
Blender object to be linked.
- collectionbpy.types.Collection or str
Collection or name of collection to link the object to.
Notes
If no collection exists with the given name, a new one will be created.
- ddg.blender.object.delete(bobj)[source]
Delete a Blender object.
- Parameters:
- bobjbpy.types.Object
Blender object to be deleted.
- ddg.blender.object.copy(bobj, collection=None)[source]
Makes a Copy of a Blender object and links it.
- Parameters:
- bobjbpy.types.Object
Blender object to be duplicated.
- collectionbpy.types.Collection (default=None)
Links copy to the given collection, if None, object will not be linked.
- Returns:
- bpy.types.Curve of bpy.types.Object
- the copy of the given object.
- ddg.blender.object.set_matrix_world(bobj, matrix)[source]
Set the
matrix_worldofbobjtomatrix.- Parameters:
- bobjbpy.types.Object
Blender object to set
matrix_world.- matrixnumpy.ndarray or mathutils.Matrix
4x4 matrix.
- Raises:
- ValueError
If dimensions of matrix are not 4x4. If type of matrix is not numpy.ndarray or mathutils.Matrix.
- ddg.blender.object.matrix_world_transformation_function(matrix)[source]
Creates a function that transforms Blender objects by a matrix.
- Parameters:
- matrixnumpy.ndarray or mathutils.Matrix
4x4 matrix.
- Returns:
- object_trafoPython function
- ddg.blender.object.set_prop(bobj, prop, val)[source]
Set a single property of a Blender object.
- Parameters:
- bobjbpy.types.Object
Blender object to set prperty to.
- propstr
Name of the property.
- valany
New value of the property.
- ddg.blender.object.look_at_point(bobj, point, bobj_front=(0, -1, 0), bobj_up=(0, 0, 1), world_up=(0, 0, 1), distance=None, atol=None, rtol=None)[source]
Rotates an object such that it looks at the given point.
If a distance is given, the object is additionally translated along the viewing direction to match the given distance to the point. If no distance is given, the object remains at its position.
The default directions are set to fit the Suzanne object.
- Parameters:
- bobjbpy.types.Object
Blenders object to move.
- pointiterable of 3 floats
Point of reference to turn object.
- bobj_frontiterable of 3 floats (default=(0,-1,0))
Viewing direction of the object in the object space. That is the direction in which the object is looking in the object space.
- bobj_upiterable of 3 floats (default=(0,0,1))
Up direction of the object in the object space. That is where the top is situed in the object space.
- world_upiterable of 3 floats (default=(0,0,1))
Where the up direction should end up.
- distance: float, default=None
Distance the object should have from the point.
- atol, rtolfloat, default=None
Tolerances used to determine whether object is located at point.
If None, the global defaults will be used.
- Raises:
- ValueError
If the object is located at the target point.
- ddg.blender.object.empty(collection=None, location=array([0, 0, 0]), empty_type='PLAIN_AXES', name='root', parent=None)[source]
Creates an empty blender object.
- Parameters:
- collection: bpy.types.Collection (default=None)
Links copy to the given collection. If
None, object will not be linked.- location: numpy.ndarray (default=np.array((0, 0, 0)))
location of empty object.
- empty_type: str (default=”PLAIN_AXES”)
Viewport display style for empty object.
- name: str (default=”root”)
Name of empty object.
- parent: bpy.types.Object (default=None)
Parent of empty object.
- Returns:
- bpy.types.Object
- ddg.blender.object.clear(objects=None, do_unlink=True, deep=True)[source]
Delete all given objects.
- Parameters:
- objectsIterable of bpy.type.Object (default=None)
Objects to be deleted. If the argument is not provided or
None, all objects will be deleted.- do_unlinkbool (default=True)
Unlink objects from their collections, if needed, before deleting them.
- deepbool (default=True)
Delete the data corresponding to the object.
- ddg.blender.object.clear_empty_objects(do_unlink=True, deep=True)[source]
Delete all empty objects.
- Parameters:
- do_unlinkbool (default=True)
Unlink objects from their collections, if needed, before deleting them.
- deepbool (default=True)
Delete the data corresponding to the object.
- ddg.blender.object.clear_lattices(lattices=None, do_unlink=True)[source]
Delete all given lattices.
- Parameters:
- latticesIterable of bpy.type.Lattice (default=None)
Lattices to be deleted. If the argument is not provided or
None, all lattices will be deleted.- do_unlinkbool (default=True)
Unlink lattices from their scenes, if needed, before deleting them.
- ddg.blender.object.get_data(x)[source]
Return the data attribute if it exists or the input itself.
- Parameters:
- xAny
- Returns:
- Any
Examples
>>> import bpy >>> from ddg.blender.object import get_data >>> >>> bpy.ops.mesh.primitive_cube_add() {'FINISHED'} >>> data = bpy.context.object.data >>> assert data == get_data(bpy.context.object) >>> assert data == get_data(bpy.context.object.data)