Skip to content

LayerInstance class

A layer instance is a frame where there is a drawing. It only has a start frame.

Note

LayerInstance is special because we can't track their position, meaning that if the user move an instance the Python object values won't match.

name: str property writable

Get or set the instance name.

length: int property writable

Get or set the instance's number of frames or length.

Raises:

Type Description
ValueError

If the length provided is inferior to 1

end: int property writable

Get or set the instance's end frame.

Raises:

Type Description
ValueError

If the end frame provided is inferior to the instance's start frame

next: LayerInstance | None property

Returns the next instance.

Returns:

Type Description
pytvpaint.layer.LayerInstance | None

the next instance or None if at the end of the layer

previous: LayerInstance | None property

Get the previous instance.

Returns:

Type Description
pytvpaint.layer.LayerInstance | None

the previous instance, None if there isn't

split(at_frame: int) -> LayerInstance

Split the instance into two instances at the given frame.

Parameters:

Name Type Description Default
at_frame int

the frame where the split will occur

required

Raises:

Type Description
ValueError

If at_frame is superior to the instance's end frame

Returns:

Name Type Description
LayerInstance pytvpaint.layer.LayerInstance

the new layer instance

Source code in pytvpaint/layer.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def split(self, at_frame: int) -> LayerInstance:
    """Split the instance into two instances at the given frame.

    Args:
        at_frame: the frame where the split will occur

    Raises:
        ValueError: If `at_frame` is superior to the instance's end frame

    Returns:
        LayerInstance: the new layer instance
    """
    if at_frame > self.end:
        raise ValueError(
            f"`at_frame` must be in range of the instance's start-end ({self.start}-{self.end})"
        )

    self.layer.make_current()
    real_frame = at_frame - self.layer.project.start_frame
    george.tv_exposure_break(real_frame)

    return LayerInstance(self.layer, at_frame)

duplicate(direction: george.InsertDirection = george.InsertDirection.AFTER) -> None

Duplicate the instance and insert it in the given direction.

Source code in pytvpaint/layer.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def duplicate(
    self, direction: george.InsertDirection = george.InsertDirection.AFTER
) -> None:
    """Duplicate the instance and insert it in the given direction."""
    self.layer.make_current()

    # tvp won't insert images if the insert frame is the same as the instance start, let's move it
    move_frame = self.layer.clip.current_frame
    if move_frame == self.start and self.layer.start != self.start:
        move_frame = self.layer.start
    else:
        move_frame = self.layer.end + 1

    with utils.restore_current_frame(self.layer.clip, move_frame):
        self.copy()
        at_frame = (
            self.end if direction == george.InsertDirection.AFTER else self.start
        )
        self.paste(at_frame=at_frame)

cut() -> None

Cut all the frames/images/exposures of the instance and store them in the image buffer.

Source code in pytvpaint/layer.py
153
154
155
156
157
def cut(self) -> None:
    """Cut all the frames/images/exposures of the instance and store them in the image buffer."""
    self.layer.make_current()
    self.select()
    self.layer.cut_selection()

copy() -> None

Copy all the frames/images/exposures of the instance and store them in the image buffer.

Source code in pytvpaint/layer.py
159
160
161
162
163
def copy(self) -> None:
    """Copy all the frames/images/exposures of the instance and store them in the image buffer."""
    self.layer.make_current()
    self.select()
    self.layer.copy_selection()

paste(at_frame: int | None) -> None

Paste all the frames/images/exposures stored in the image buffer to the current instance at the given frame.

Parameters:

Name Type Description Default
at_frame int | None

the frame where the stored frames will be pasted. Default is the current frame

required
Source code in pytvpaint/layer.py
165
166
167
168
169
170
171
172
173
174
175
def paste(self, at_frame: int | None) -> None:
    """Paste all the frames/images/exposures stored in the image buffer to the current instance at the given frame.

    Args:
        at_frame: the frame where the stored frames will be pasted. Default is the current frame
    """
    at_frame = at_frame if at_frame is not None else self.layer.clip.current_frame

    self.layer.make_current()
    with utils.restore_current_frame(self.layer.clip, at_frame):
        self.layer.paste_selection()

select() -> None

Select all frames in this instance.

Source code in pytvpaint/layer.py
177
178
179
def select(self) -> None:
    """Select all frames in this instance."""
    self.layer.select_frames(self.start, (self.length - 1))