databpy 0.13.0
  • Home
  • Guides
    • Attributes
    • Syncing with Blender
    • Grease pencil and evaluated geometry
  • API
  • Changelog
  1. Objects
  2. create_grease_pencil_object
  • Function reference
  • Attribute
    • named_attribute
    • store_named_attribute
    • remove_named_attribute
    • list_attributes
    • AttributeDomains
    • AttributeTypes
    • AttributeArray
    • Attribute
    • attribute.guess_atype_from_array
  • Typed arrays
    • float32
    • vec2
    • vec3
    • vec4
    • color
    • srgb
    • color8
    • quat
    • mat4
    • int32
    • int8
    • ivec2
    • sivec2
    • boolean
    • string
  • Collections
    • create_collection
    • move_to_collection
  • Objects
    • create_object
    • create_mesh_object
    • create_curves_object
    • create_grease_pencil_object
    • create_pointcloud_object
    • create_bob
    • evaluate_object
    • GeometrySet
    • BlenderObject
    • AttributeDomainView
    • InstanceDomainView
    • Drawing
    • Drawings
    • BlenderObjectAttribute
    • BlenderObjectBase
  • Errors
    • DatabpyError
    • NamedAttributeError
    • AttributeNotFoundError
    • AttributeMismatchError
    • LinkedObjectError
  • Utilities
    • require
    • require_data
    • mesh_data
    • curves_data
    • pointcloud_data
    • volume_data
    • active_scene
    • active_object
    • centre
    • lerp
  • Nodes (deprecated)
    • nodes.new_tree
    • nodes.swap_tree
    • nodes.custom_string_iswitch
    • nodes.append_from_blend
    • nodes.new_socket
    • nodes.tree_interface
    • nodes.input_socket
    • nodes.output_socket
    • nodes.socket_value
    • nodes.set_socket_value
    • nodes.MaintainConnections
    • nodes.DuplicatePrevention

On this page

  • create_grease_pencil_object
    • Parameters
    • Returns
    • Raises
    • Examples
  1. Objects
  2. create_grease_pencil_object

create_grease_pencil_object

create_grease_pencil_object(layers=None, name='GreasePencil', collection=None)

Create a new Blender grease pencil object.

Each layer gets one drawing on the scene’s current frame, holding its strokes. The drawing is only shown from that frame onwards, so a layer created on frame 10 has no drawing on frame 1. A layer with no strokes gets an empty drawing.

Parameters

Name Type Description Default
layers Mapping[str, tuple[np.ndarray, list[int] | np.ndarray]] The layers to create, mapping each layer’s name to the positions of its points with shape (N, 3) and the number of points in each stroke. If None, creates an empty grease pencil object. Defaults to None. None
name str The name of the object. Defaults to ‘GreasePencil’. 'GreasePencil'
collection bpy.types.Collection The collection to link the object to. Defaults to None, which links it to a collection named “Collection”, created if needed. None

Returns

Name Type Description
Object The created grease pencil object.

Raises

Name Type Description
ValueError If the positions of a layer don’t have shape (N, 3), a stroke has fewer than 1 point, or the stroke sizes of a layer don’t add up to the number of its positions. Every layer is checked before anything is created.

Examples

import numpy as np
from databpy import create_grease_pencil_object

# Create two layers, with 2 strokes and 1 stroke
gp_obj = create_grease_pencil_object(
    {
        "Lines": (np.random.random((7, 3)), [3, 4]),
        "Outline": (np.random.random((5, 3)), [5]),
    }
)
create_curves_object
create_pointcloud_object