Skip to content

linkcad.edit

Geometry manipulation tasks. Each task operates on a Drawing and is executed by calling task.execute(). Tasks must be run inside a WriteLock (standalone scripts) or a Transaction (tool plugins).

from linkcad.edit import (
ITask,
SnapToGridTask,
FlattenTask,
RemoveDuplicatesTask,
MergeTask,
ClosePolylinesTask,
JoinPolylinesTask,
PolylineToPolygonTask,
ExplodeToPolygonTask,
RemoveZeroWidthPolylinesTask,
RemoveOverlappingPolylinesTask,
FixSelfIntersectingPolygonsTask,
FillRule,
HolesMode,
EdgePolicy,
PolygonSnapMode,
)

Base Class

ITask

All tasks extend ITask.

MethodDescription
task.execute()Run the task on the drawing

Tasks

SnapToGridTask

Snaps all shape vertices to the nearest grid point.

from linkcad.edit import SnapToGridTask, PolygonSnapMode
from linkcad.geom import Resolution
task = SnapToGridTask(drawing, resolution, grid_x, grid_y, PolygonSnapMode.Nearest)
task.execute()
ParameterTypeDescription
drawingDrawingTarget drawing
resolutionResolutionCurve tessellation settings
grid_xintGrid spacing in X (database units)
grid_yintGrid spacing in Y (database units)
snap_modePolygonSnapModeHow to handle polygon vertices

FlattenTask

Flattens the cell hierarchy — expands all cell references into their parent cells.

from linkcad.edit import FlattenTask
from linkcad.geom import Resolution
task = FlattenTask(drawing, resolution)
task.execute()

RemoveDuplicatesTask

Removes exact duplicate shapes from the drawing.

from linkcad.edit import RemoveDuplicatesTask
task = RemoveDuplicatesTask(drawing)
task.execute()

MergeTask

Merges overlapping polygons on each layer using a boolean union operation. Circles and other curved shapes are tessellated first using the provided Resolution.

from linkcad.edit import MergeTask, FillRule, HolesMode, EdgePolicy
from linkcad.geom import Resolution
res = Resolution()
res.minimum_facets = 32
res.maximum_error = 1
task = MergeTask(
drawing,
res,
FillRule.NonZero,
HolesMode.Link,
EdgePolicy.Merge,
dont_explode=False,
process_vertically=False,
)
task.execute()
ParameterTypeDescription
drawingDrawingTarget drawing
resolutionResolutionCurve tessellation settings
fill_ruleFillRuleWinding rule for determining polygon interior
holes_modeHolesModeHow to represent holes in output polygons
edge_policyEdgePolicyHow to handle touching/overlapping edges
dont_explodeboolIf True, do not decompose complex result polygons
process_verticallyboolIf True, process cells bottom-up (for hierarchical drawings)

ClosePolylinesTask

Closes all open polylines by connecting their endpoints.

from linkcad.edit import ClosePolylinesTask
task = ClosePolylinesTask(drawing)
task.execute()

JoinPolylinesTask

Joins polylines whose endpoints are touching or within tolerance.

from linkcad.edit import JoinPolylinesTask
task = JoinPolylinesTask(drawing)
task.execute()

PolylineToPolygonTask

Converts closed polylines to filled polygons.

from linkcad.edit import PolylineToPolygonTask
task = PolylineToPolygonTask(drawing)
task.execute()

ExplodeToPolygonTask

Converts all shapes (circles, arcs, donuts, ellipses, NURBS) to plain polygons/polylines by tessellation.

from linkcad.edit import ExplodeToPolygonTask
from linkcad.geom import Resolution
res = Resolution()
res.minimum_facets = 32
task = ExplodeToPolygonTask(drawing, res)
task.execute()

RemoveZeroWidthPolylinesTask

Deletes all polylines with a width of zero.

from linkcad.edit import RemoveZeroWidthPolylinesTask
task = RemoveZeroWidthPolylinesTask(drawing)
task.execute()

RemoveOverlappingPolylinesTask

Removes polyline segments that exactly overlap other segments on the same layer.

from linkcad.edit import RemoveOverlappingPolylinesTask
task = RemoveOverlappingPolylinesTask(drawing)
task.execute()

FixSelfIntersectingPolygonsTask

Detects and repairs self-intersecting polygons, splitting them into valid non-self-intersecting parts.

from linkcad.edit import FixSelfIntersectingPolygonsTask
from linkcad.geom import Resolution
task = FixSelfIntersectingPolygonsTask(drawing, res)
task.execute()

Enums

FillRule

Winding rule used when determining which regions are “inside” a polygon during merge.

ValueDescription
FillRule.NonZeroNon-zero winding rule (standard CAD/EDA convention)
FillRule.EvenOddEven-odd (alternating fill) rule

HolesMode

Controls how holes in merged polygons are represented in the output.

ValueDescription
HolesMode.ExtractRepresent holes as separate polygons
HolesMode.LinkLink holes to outer boundary with zero-width bridges
HolesMode.SplitSplit polygons so no holes appear in output

EdgePolicy

Controls how coincident or touching edges are handled during merge.

ValueDescription
EdgePolicy.MergeMerge touching edges

PolygonSnapMode

Controls how vertices are snapped to the grid.

ValueDescription
PolygonSnapMode.NearestSnap each vertex to the nearest grid point