跳转到主要内容

raygeo.ops

Command sequence (Ops) manipulation for laser cutter motion control.

Ops is a container of ordered commands (move, line, arc, bezier, state changes like power/speed) that defines a complete laser engraving or cutting job. It supports building sequences programmatically (move_to, line_to, arc_to, etc.), transforming them (translate, rotate, scale, transform with 4x4 matrices), clipping to rectangles or regions, linearizing curves, estimating processing time, and serializing to dict or numpy arrays for persistence.

The module also provides command-type enumerations (CommandType, CommandCategory, SectionType), machine State tracking (power, speed, air assist, frequency), and an Axis bitflag for multi-axis machines.

CommandInfo

Detailed information about a single command in an Ops sequence.

Returned by Ops.inspect and provides the full set of parameters for any command type in a structured form.

center_offset

center_offset: Optional[tuple[float, float]]

clockwise

clockwise: Optional[bool]

control

control: Optional[tuple[float, float, float]]

control1

control1: Optional[tuple[float, float, float]]

control2

control2: Optional[tuple[float, float, float]]

duration_ms

duration_ms: Optional[float]

end

end: Optional[tuple[float, float, float]]

extra_axes

extra_axes: Optional[dict]

frequency

frequency: Optional[int]

laser_uid

laser_uid: Optional[str]

layer_uid

layer_uid: Optional[str]

power

power: Optional[float]

power_values

power_values: Optional[bytes]

pulse_width

pulse_width: Optional[float]

section_type

section_type: Optional[str]

speed

speed: Optional[int]

state

state: Optional[state.State]

type_

type_: types.CommandType

workpiece_uid

workpiece_uid: Optional[str]

Ops

A sequence of laser cutting operations (commands).

Ops is a container of ordered commands that define a complete laser engraving or cutting job. It supports building command sequences programmatically, transforming them, clipping, serializing, and more.

Use the builder methods (move_to, line_to, arc_to, etc.) to construct a sequence, or load from geometry/dict/numpy arrays.

last_move_to

last_move_to: tuple[float, float, float]

The last (x, y, z) endpoint from a MoveTo command.

scanline_count

scanline_count: int

Return the number of scanline commands in the sequence.

arc_params()

arc_params(idx: int) -> tuple[float, float, bool]

Get the arc parameters (center offset i, j, and clockwise flag).

Returns: (i, j, clockwise) tuple.

Raises: TypeError — If the command is not an ArcTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[float, float, bool]

arc_to()

arc_to(x: float, y: float, i: float, j: float, clockwise: bool = True, z: float = 0.0, extra: Optional[dict] = None) -> None

Add a circular arc to the given coordinates.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
ifloatI offset from current point to arc center.
jfloatJ offset from current point to arc center.
clockwisebool = TrueWhether the arc is clockwise (default True).
zfloat = 0.0End Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

bezier_params()

bezier_params(idx: int) -> tuple[tuple[float, float, float], tuple[float, float, float]]

Get the cubic bezier control points.

Returns: ((c1x, c1y, c1z), (c2x, c2y, c2z)) control points.

Raises: TypeError — If the command is not a BezierTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[tuple[float, float, float], tuple[float, float, float]]

bezier_to()

bezier_to(c1: tuple[float, float, float], c2: tuple[float, float, float], end: tuple[float, float, float], extra: Optional[dict] = None) -> None

Add a cubic bezier curve to the given endpoint.

ParameterTypeDescription
c1tuple[float, float, float]First control point (x, y, z).
c2tuple[float, float, float]Second control point (x, y, z).
endtuple[float, float, float]End point (x, y, z).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

category()

category(idx: int) -> types.CommandCategory

Get the CommandCategory at the given index.

Returns: The category (MOVING, STATE, or MARKER).

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstypes.CommandCategory

clear()

clear() -> None

Remove all commands from this Ops sequence.

ParameterTypeDescription
ReturnsNone

clip_at()

clip_at(x: float, y: float, width: float) -> bool

Clip at a single vertical swath, keeping commands that intersect the band.

Returns: True if any commands were kept.

ParameterTypeDescription
xfloatX coordinate of the left edge.
yfloatY coordinate (used to find the relevant segment).
widthfloatWidth of the band.
Returnsbool

clip_ops_to_regions()

clip_ops_to_regions(regions: Sequence[Sequence[tuple[float, float]]], tolerance: float = 0.3) -> None

Clip paths using polygonal regions as boundaries; keeps what is inside.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
tolerancefloat = 0.3Approximation tolerance (default 0.3).
ReturnsNone

clip_rect()

clip_rect(rect: tuple[float, float, float, float]) -> Ops

Clip this sequence to a rectangle, keeping only commands inside.

Returns: A new Ops sequence containing the clipped commands.

ParameterTypeDescription
recttuple[float, float, float, float](x_min, y_min, x_max, y_max).
ReturnsOps

clip_to_regions()

clip_to_regions(regions: Sequence[Sequence[tuple[float, float]]], tolerance: float = 0.3) -> None

Clip paths to the given polygonal regions, keeping only what is inside.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
tolerancefloat = 0.3Approximation tolerance (default 0.3).
ReturnsNone

close_path()

close_path() -> None

Close the current sub-path by adding a line back to the start.

ParameterTypeDescription
ReturnsNone

command_type()

command_type(idx: int) -> types.CommandType

Get the CommandType at the given index.

Returns: The CommandType of the command.

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstypes.CommandType

copy()

copy() -> Ops

Return a deep copy of this Ops sequence.

ParameterTypeDescription
ReturnsOps

copy_command_from()

copy_command_from(source: Ops, idx: int) -> None

Copy a single command from another Ops sequence into this one.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
idxintIndex of the command to copy.
ReturnsNone

cut_distance()

cut_distance() -> float

Compute the total cutting distance (excluding travel moves).

ParameterTypeDescription
Returnsfloat

disable_air_assist()

disable_air_assist() -> None

Disable air assist.

ParameterTypeDescription
ReturnsNone

distance()

distance() -> float

Compute the total distance of all commands.

ParameterTypeDescription
Returnsfloat

distance_at()

distance_at(idx: int, last_point: Optional[tuple[float, float, float]] = None) -> float

Compute the distance traveled up to command idx.

Returns: Cumulative distance.

ParameterTypeDescription
idxintCommand index.
last_pointOptional[tuple[float, float, float]] = NoneOptional starting point override.
Returnsfloat

dump()

dump() -> None

Print a human-readable dump of all commands.

ParameterTypeDescription
ReturnsNone

dwell()

dwell(duration_ms: float) -> None

Pause execution for a given duration.

ParameterTypeDescription
duration_msfloatDwell duration in milliseconds.
ReturnsNone

dwell_duration()

dwell_duration(idx: int) -> float

Get the duration (milliseconds) of a Dwell command.

Returns: Duration in milliseconds.

Raises: TypeError — If the command is not a Dwell.

ParameterTypeDescription
idxintCommand index.
Returnsfloat

enable_air_assist()

enable_air_assist() -> None

Enable air assist for subsequent cutting.

ParameterTypeDescription
ReturnsNone

endpoint()

endpoint(idx: int) -> tuple[float, float, float]

Get the endpoint coordinates of a moving command.

Returns: (x, y, z) tuple.

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstuple[float, float, float]

estimate_time()

estimate_time(default_cut_speed: float = 1000.0, default_travel_speed: float = 3000.0, acceleration: float = 1000.0) -> float

Estimate the total processing time for this sequence.

Returns: Estimated time in seconds.

ParameterTypeDescription
default_cut_speedfloat = 1000.0Default cutting speed (default 1000.0).
default_travel_speedfloat = 3000.0Default travel speed (default 3000.0).
accelerationfloat = 1000.0Acceleration value (default 1000.0).
Returnsfloat

extend()

extend(other: Optional[Ops]) -> None

Extend this Ops sequence with commands from another.

ParameterTypeDescription
otherOptional[Ops]The other Ops sequence (or None for no-op).
ReturnsNone

extra_axes()

extra_axes(idx: int) -> Optional[dict]

Get the extra axes data for a moving command.

Returns: Dict mapping axis names to values, or None.

ParameterTypeDescription
idxintCommand index.
ReturnsOptional[dict]

flip_ops()

flip_ops() -> Ops

Reverse the order of subpaths.

Returns: A new Ops with subpath order reversed.

ParameterTypeDescription
ReturnsOps

frequency()

frequency(idx: int) -> int

Get the frequency of a SetFrequency command.

Returns: Frequency in Hz.

Raises: TypeError — If the command is not a SetFrequency.

ParameterTypeDescription
idxintCommand index.
Returnsint

from_dict()

@classmethod from_dict(data: dict) -> Ops

Create an Ops sequence from a dictionary.

ParameterTypeDescription
datadictDictionary as produced by to_dict.
ReturnsOps

from_geometry()

@classmethod from_geometry(geometry: geo.Geometry) -> Ops

Create an Ops sequence from a Geometry.

ParameterTypeDescription
geometrygeo.GeometryThe geometry to convert.
ReturnsOps

from_numpy_arrays()

@classmethod from_numpy_arrays(arrays: dict) -> Ops

Create an Ops sequence from numpy arrays.

ParameterTypeDescription
arraysdictDictionary as produced by to_numpy_arrays.
ReturnsOps

get_frame()

get_frame(power: Optional[float] = None, speed: Optional[float] = None) -> Ops

Extract a frame (first and last endpoints) from the sequence.

Returns: A new Ops containing only the frame endpoints.

ParameterTypeDescription
powerOptional[float] = NoneOptional power to set on the frame commands.
speedOptional[float] = NoneOptional speed to set on the frame commands.
ReturnsOps

group_by_state_continuity()

group_by_state_continuity() -> list[Ops]

Group contiguous commands with the same state into separate Ops sequences.

Returns: A list of Ops sequences grouped by state continuity.

ParameterTypeDescription
Returnslist[Ops]

indices_of()

indices_of(ct: types.CommandType) -> list[int]

Return all indices where the command type matches ct.

Returns: List of matching command indices.

ParameterTypeDescription
cttypes.CommandTypeThe CommandType to search for.
Returnslist[int]

inspect()

inspect(idx: int) -> CommandInfo

Return detailed information about a single command.

Returns: A CommandInfo object with type, endpoint, state, axes, etc.

ParameterTypeDescription
idxintThe command index.
ReturnsCommandInfo

is_cutting()

is_cutting(idx: int) -> bool

Check whether the command at idx is a cutting move.

Returns: True if the command is a cutting move.

ParameterTypeDescription
idxintCommand index.
Returnsbool

is_empty()

is_empty() -> bool

Check if the ops sequence is empty.

ParameterTypeDescription
Returnsbool

is_marker()

is_marker(idx: int) -> bool

Check whether the command at idx is a marker command.

Returns: True if the command is a structural marker (JobStart, LayerStart, etc.).

ParameterTypeDescription
idxintCommand index.
Returnsbool

is_scanline()

is_scanline(idx: int) -> bool

Check whether the command at idx is a scanline command.

Returns: True if the command is a ScanLine power command.

ParameterTypeDescription
idxintCommand index.
Returnsbool

is_state()

is_state(idx: int) -> bool

Check whether the command at idx is a state command.

Returns: True if the command modifies machine state.

ParameterTypeDescription
idxintCommand index.
Returnsbool

is_travel()

is_travel(idx: int) -> bool

Check whether the command at idx is a travel (non-cutting) move.

Returns: True if the command is a travel move.

ParameterTypeDescription
idxintCommand index.
Returnsbool

job_end()

job_end() -> None

Mark the end of a job.

ParameterTypeDescription
ReturnsNone

job_start()

job_start() -> None

Mark the start of a job.

ParameterTypeDescription
ReturnsNone

laser_uid()

laser_uid(idx: int) -> str

Get the laser UID from a SetLaser command.

Returns: The laser source identifier.

Raises: TypeError — If the command is not a SetLaser.

ParameterTypeDescription
idxintCommand index.
Returnsstr

layer_end()

layer_end(layer_uid: str) -> None

Mark the end of a layer.

ParameterTypeDescription
layer_uidstrThe layer identifier.
ReturnsNone

layer_start()

layer_start(layer_uid: str) -> None

Mark the start of a layer.

ParameterTypeDescription
layer_uidstrThe layer identifier.
ReturnsNone

layer_uid()

layer_uid(idx: int) -> str

Get the layer UID from a LayerStart or LayerEnd command.

Returns: The layer identifier.

Raises: TypeError — If the command is not a Layer command.

ParameterTypeDescription
idxintCommand index.
Returnsstr

len()

len() -> int

Return the number of commands.

ParameterTypeDescription
Returnsint

line_to()

line_to(x: float, y: float, z: float = 0.0, extra: Optional[dict] = None) -> None

Add a cutting line to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

linearize()

linearize(idx: int, start_point: tuple[float, float, float]) -> Ops

Decompose a curved command into linear segments.

Returns: A new Ops containing the linearized sub-commands.

Raises: TypeError — If the command at idx is not a curve or line type.

ParameterTypeDescription
idxintIndex of the command to linearize.
start_pointtuple[float, float, float]The (x, y, z) start point of the curve.
ReturnsOps

linearize_all()

linearize_all() -> None

Replace all curved commands with linear approximations in-place.

ParameterTypeDescription
ReturnsNone

linearize_arcs()

linearize_arcs() -> None

Replace only arc commands with linear approximations.

ParameterTypeDescription
ReturnsNone

linearize_curves()

linearize_curves() -> None

Replace only bezier and quadratic bezier curves with linear approximations.

ParameterTypeDescription
ReturnsNone

move_to()

move_to(x: float, y: float, z: float = 0.0, extra: Optional[dict] = None) -> None

Add a rapid (non-cutting) move to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

ops_section_end()

ops_section_end(section_type: types.SectionType) -> None

Mark the end of an ops section.

ParameterTypeDescription
section_typetypes.SectionTypeThe type of section.
ReturnsNone

ops_section_start()

ops_section_start(section_type: types.SectionType, workpiece_uid: str) -> None

Mark the start of an ops section.

ParameterTypeDescription
section_typetypes.SectionTypeThe type of section.
workpiece_uidstrThe workpiece identifier.
ReturnsNone

power()

power(idx: int) -> float

Get the power level of a SetPower command.

Returns: Power level (0.0–1.0 typically).

Raises: TypeError — If the command is not a SetPower.

ParameterTypeDescription
idxintCommand index.
Returnsfloat

preload_state()

preload_state() -> None

Pre-compute and store the accumulated state at each moving command.

ParameterTypeDescription
ReturnsNone

preloaded_state()

preloaded_state(idx: int) -> Optional[state.State]

Get the preloaded machine state for a moving command (if available).

The preloaded state is the state that was in effect at the time this command was created (after calling preload_state).

Returns: The State at that index, or None.

ParameterTypeDescription
idxintCommand index.
ReturnsOptional[state.State]

pulse_width()

pulse_width(idx: int) -> float

Get the pulse width of a SetPulseWidth command.

Returns: Pulse width in microseconds.

Raises: TypeError — If the command is not a SetPulseWidth.

ParameterTypeDescription
idxintCommand index.
Returnsfloat

quadratic_bezier_params()

quadratic_bezier_params(idx: int) -> tuple[float, float, float]

Get the quadratic bezier control point.

Returns: (cx, cy, cz) control point.

Raises: TypeError — If the command is not a QuadraticBezierTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[float, float, float]

quadratic_bezier_to()

quadratic_bezier_to(control: tuple[float, float, float], end: tuple[float, float, float], extra: Optional[dict] = None) -> None

Add a quadratic bezier curve to the given endpoint.

ParameterTypeDescription
controltuple[float, float, float]Control point (x, y, z).
endtuple[float, float, float]End point (x, y, z).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

rect()

rect(include_travel: bool = False) -> tuple[float, float, float, float]

Compute the bounding rectangle of all commands.

Returns: (x_min, y_min, x_max, y_max).

ParameterTypeDescription
include_travelbool = FalseWhether to include travel moves (default False).
Returnstuple[float, float, float, float]

replace_all()

replace_all(source: Ops) -> None

Replace all commands in this sequence with those from another.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
ReturnsNone

replace_with()

replace_with(source: Ops) -> None

Replace the internal buffer of this sequence with a copy from another.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
ReturnsNone

rotate()

rotate(angle_deg: float, cx: float, cy: float) -> None

Rotate all coordinates around a pivot point.

ParameterTypeDescription
angle_degfloatRotation angle in degrees.
cxfloatPivot X coordinate.
cyfloatPivot Y coordinate.
ReturnsNone

scale()

scale(sx: float, sy: float, sz: float) -> None

Scale all coordinates by the given factors.

ParameterTypeDescription
sxfloatX scale factor.
syfloatY scale factor.
szfloatZ scale factor.
ReturnsNone

scan_to()

scan_to(x: float, y: float, z: float = 0.0, power_values: Optional[Sequence[int]] = None, extra: Optional[dict] = None) -> None

Add a scan-line move with per-pixel power values.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
zfloat = 0.0End Z coordinate (default 0.0).
power_valuesOptional[Sequence[int]] = NoneOptional per-pixel 8-bit power values.
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone

scanline_data()

scanline_data(idx: int) -> bytes

Get the raw scanline power data for a scanline command.

Returns: Raw bytes of scanline power data.

ParameterTypeDescription
idxintCommand index.
Returnsbytes

section_params()

section_params(idx: int) -> tuple[types.SectionType, Optional[str]]

Get the section type and optional workpiece UID from an OpsSection command.

Returns: (SectionType, Optional[workpiece_uid]).

Raises: TypeError — If the command is not an OpsSectionStart or OpsSectionEnd.

ParameterTypeDescription
idxintCommand index.
Returnstuple[types.SectionType, Optional[str]]

section_ranges()

section_ranges() -> list[OpsSectionRange]

Return the section ranges of the ops as index ranges.

Similar to sections but returns contiguous index ranges instead of individual index lists.

Returns: List of OpsSectionRange objects.

ParameterTypeDescription
Returnslist[OpsSectionRange]

sections()

sections() -> list[OpsSection]

Return the logical sections of the ops.

Sections are delimited by OpsSectionStart/OpsSectionEnd markers and group commands into vector-outline and raster-fill portions.

Returns: List of OpsSection objects.

ParameterTypeDescription
Returnslist[OpsSection]

segment_indices()

segment_indices() -> list[list[int]]

Return index ranges for each contiguous cutting segment.

Returns: A list of index lists, one per segment.

ParameterTypeDescription
Returnslist[list[int]]

segments()

segments() -> list[list[int]]

Return index ranges for cutting segments (runs of moving commands separated by travel).

Returns: A list of index lists, one per cutting segment.

ParameterTypeDescription
Returnslist[list[int]]

set_cut_speed()

set_cut_speed(speed: int) -> None

Set the cutting speed for subsequent commands.

ParameterTypeDescription
speedintCutting speed in units per second.
ReturnsNone

set_frequency()

set_frequency(frequency: int) -> None

Set the laser pulse frequency.

ParameterTypeDescription
frequencyintFrequency in Hz.
ReturnsNone

set_laser()

set_laser(laser_uid: str) -> None

Switch to a specific laser by UID.

ParameterTypeDescription
laser_uidstrThe laser identifier.
ReturnsNone

set_power()

set_power(power: float) -> None

Set the laser power for subsequent commands.

ParameterTypeDescription
powerfloatPower level (0.0–1.0).
ReturnsNone

set_pulse_width()

set_pulse_width(pulse_width: float) -> None

Set the laser pulse width.

ParameterTypeDescription
pulse_widthfloatPulse width in microseconds.
ReturnsNone

set_state_at()

set_state_at(idx: int, state: state.State) -> None

Overwrite the state at a specific command index.

ParameterTypeDescription
idxintThe command index.
statestate.StateThe new state.
ReturnsNone

set_state_on_moving()

set_state_on_moving(state: state.State) -> None

Apply a state to all moving commands without an explicit state.

ParameterTypeDescription
statestate.StateThe state to apply.
ReturnsNone

set_travel_speed()

set_travel_speed(speed: int) -> None

Set the travel (rapid) speed for subsequent commands.

ParameterTypeDescription
speedintTravel speed in units per second.
ReturnsNone

speed()

speed(idx: int) -> int

Get the speed value from a SetCutSpeed or SetTravelSpeed command.

Returns: Speed in mm/s.

Raises: TypeError — If the command is not a speed command.

ParameterTypeDescription
idxintCommand index.
Returnsint

split_into_subpaths()

split_into_subpaths() -> list[Ops]

Split this Ops sequence into separate subpaths.

Returns: A list of Ops sequences, one per subpath.

ParameterTypeDescription
Returnslist[Ops]

state_at()

state_at(idx: int) -> state.State

Return the accumulated state at a given command index.

Returns: The state at that point.

Raises: IndexError — If the index is out of range.

ParameterTypeDescription
idxintThe command index.
Returnsstate.State

sub_ops()

sub_ops(indices: Sequence[int]) -> Ops

Extract a subset of commands by index.

Returns: A new Ops sequence containing only the specified commands.

ParameterTypeDescription
indicesSequence[int]List of command indices to extract.
ReturnsOps

subpath_indices()

subpath_indices() -> list[list[int]]

Return index ranges for each subpath.

Returns: A list of index lists, one per subpath.

ParameterTypeDescription
Returnslist[list[int]]

subtract_regions()

subtract_regions(regions: Sequence[Sequence[tuple[float, float]]]) -> None

Subtract polygonal regions from the cutting paths.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
ReturnsNone

to_dict()

to_dict() -> dict

Serialize this Ops sequence to a dict suitable for JSON export.

Returns: A Python dict representation.

ParameterTypeDescription
Returnsdict

to_geometry()

to_geometry() -> geo.Geometry

Convert this Ops sequence back into a Geometry.

Returns: A Geometry representing the same paths.

ParameterTypeDescription
Returnsgeo.Geometry

to_numpy_arrays()

to_numpy_arrays() -> dict

Serialize this Ops sequence to numpy arrays.

Returns: A Python dict of numpy arrays.

ParameterTypeDescription
Returnsdict

transfer_command_from()

transfer_command_from(source: Ops, idx: int) -> None

Transfer (move) a single command from another Ops sequence into this one.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
idxintIndex of the command to transfer.
ReturnsNone

transform()

transform(matrix: geo.types.TransformMatrix) -> None

Apply a 4x4 affine transformation matrix to all geometry.

See raygeo.geo.types.TransformMatrix for the matrix layout.

ParameterTypeDescription
matrixgeo.types.TransformMatrixA 4x4 affine transformation matrix.
ReturnsNone

transform_layers()

transform_layers(callback: Any) -> None

Transform each layer by calling a Python callback with the layer UID and ops.

The callback receives (layer_uid: str, layer_ops: Ops) and should mutate the layer_ops in place.

ParameterTypeDescription
callbackAnyA callable accepting (layer_uid, layer_ops).
ReturnsNone

transform_moving()

transform_moving(on_endpoint: Any, on_aux_point: Optional[Any] = None) -> None

Transform moving commands by calling Python callbacks on each endpoint and aux point.

The on_endpoint callback receives (endpoint, extra_axes) and should mutate the endpoint list in-place. The optional on_aux_point callback receives control points for curve commands.

ParameterTypeDescription
on_endpointAnyCallable (endpoint, extra_axes) -> None.
on_aux_pointOptional[Any] = NoneOptional callable (point,) -> None for curve control points.
ReturnsNone

translate()

translate(dx: float, dy: float, dz: float = 0.0) -> None

Translate all moving commands by the given offset.

ParameterTypeDescription
dxfloatX offset.
dyfloatY offset.
dzfloat = 0.0Z offset (default 0.0).
ReturnsNone

translate_layers()

translate_layers(default_offset: tuple[float, float, float], layer_offsets: Optional[dict] = None) -> None

Translate each layer by its own offset, with a default fallback.

ParameterTypeDescription
default_offsettuple[float, float, float]The (x, y, z) offset for layers not listed in layer_offsets.
layer_offsetsOptional[dict] = NoneOptional dict mapping layer UIDs to (x, y, z) offsets.
ReturnsNone

without_state()

without_state() -> Ops

Return a copy with all state commands removed.

Returns: A new Ops containing only moving commands.

ParameterTypeDescription
ReturnsOps

workpiece_end()

workpiece_end(workpiece_uid: str) -> None

Mark the end of a workpiece.

ParameterTypeDescription
workpiece_uidstrThe workpiece identifier.
ReturnsNone

workpiece_start()

workpiece_start(workpiece_uid: str) -> None

Mark the start of a workpiece.

ParameterTypeDescription
workpiece_uidstrThe workpiece identifier.
ReturnsNone

workpiece_uid()

workpiece_uid(idx: int) -> str

Get the workpiece UID from a WorkpieceStart or WorkpieceEnd command.

Returns: The workpiece identifier.

Raises: TypeError — If the command is not a Workpiece command.

ParameterTypeDescription
idxintCommand index.
Returnsstr

OpsSection

A section of operations parsed into marker and content index groups.

Produced by Ops.sections when splitting an Ops sequence into logical sections based on OpsSectionStart/OpsSectionEnd markers.

content_indices

content_indices: list[int]

Indices of the content commands belonging to this section.

marker_indices

marker_indices: list[int]

Indices of the section-marker commands (start/end) for this section.

section_type

section_type: Optional[types.SectionType]

The type of this section (VectorOutline or RasterFill), if any.

OpsSectionRange

A contiguous range of indices that belong to a section.

Similar to OpsSection but stores start/end index ranges instead of individual index lists. Produced by Ops.section_ranges.

content_indices

content_indices: list[int]

Starting index of the content within this section range.

marker_indices

marker_indices: list[int]

Indices of the section-marker commands that bracket this range.

section_type

section_type: Optional[types.SectionType]

The type of this section range (VectorOutline or RasterFill), if any.