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.
| Method | Description |
|---|---|
task.execute() | Run the task on the drawing |
Tasks
SnapToGridTask
Snaps all shape vertices to the nearest grid point.
from linkcad.edit import SnapToGridTask, PolygonSnapModefrom linkcad.geom import Resolution
task = SnapToGridTask(drawing, resolution, grid_x, grid_y, PolygonSnapMode.Nearest)task.execute()| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
resolution | Resolution | Curve tessellation settings |
grid_x | int | Grid spacing in X (database units) |
grid_y | int | Grid spacing in Y (database units) |
snap_mode | PolygonSnapMode | How to handle polygon vertices |
FlattenTask
Flattens the cell hierarchy — expands all cell references into their parent cells.
from linkcad.edit import FlattenTaskfrom 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, EdgePolicyfrom linkcad.geom import Resolution
res = Resolution()res.minimum_facets = 32res.maximum_error = 1
task = MergeTask( drawing, res, FillRule.NonZero, HolesMode.Link, EdgePolicy.Merge, dont_explode=False, process_vertically=False,)task.execute()| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
resolution | Resolution | Curve tessellation settings |
fill_rule | FillRule | Winding rule for determining polygon interior |
holes_mode | HolesMode | How to represent holes in output polygons |
edge_policy | EdgePolicy | How to handle touching/overlapping edges |
dont_explode | bool | If True, do not decompose complex result polygons |
process_vertically | bool | If 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 ExplodeToPolygonTaskfrom 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 FixSelfIntersectingPolygonsTaskfrom 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.
| Value | Description |
|---|---|
FillRule.NonZero | Non-zero winding rule (standard CAD/EDA convention) |
FillRule.EvenOdd | Even-odd (alternating fill) rule |
HolesMode
Controls how holes in merged polygons are represented in the output.
| Value | Description |
|---|---|
HolesMode.Extract | Represent holes as separate polygons |
HolesMode.Link | Link holes to outer boundary with zero-width bridges |
HolesMode.Split | Split polygons so no holes appear in output |
EdgePolicy
Controls how coincident or touching edges are handled during merge.
| Value | Description |
|---|---|
EdgePolicy.Merge | Merge touching edges |
PolygonSnapMode
Controls how vertices are snapped to the grid.
| Value | Description |
|---|---|
PolygonSnapMode.Nearest | Snap each vertex to the nearest grid point |