linkcad.edit
Geometry manipulation tasks. Each task is constructed against a Drawing (or, for FlattenTask, a Cell) and is run by calling task.execute(). Tasks must be run inside a WriteLock (standalone scripts) or a Transaction (tool plugins).
from linkcad.v1.edit import ( ITask, SnapToGridTask, FlattenTask, RemoveDuplicatesTask, MergeTask, ClosePolylinesTask, JoinPolylinesTask, PolylineToPolygonTask, ExplodeToPolygonTask, RemoveZeroWidthPolylinesTask, RemoveOverlappingPolylinesTask, FixSelfIntersectingPolygonsTask, FillRule, HolesMode, EdgePolicy, PolygonSnapMode, ShapesToConvert, CellFilter, LayerFilter, ShapeFilter,)Base Class
ITask
All tasks extend ITask.
| Property / Method | Description |
|---|---|
task.execute() | Run the task. May raise on failure |
task.cancel() | Cancel a running task |
task.progress | Progress percentage (0-100) |
task.cell_filter | Which cells the task processes; assignable |
task.layer_filter | Which layers the task includes; assignable |
task.shape_filter | Which shapes the task includes; assignable |
from linkcad.v1.edit import CellFilter, RemoveDuplicatesTask, ShapeFilter
task = RemoveDuplicatesTask(drawing)task.cell_filter = CellFilter.EnabledCellstask.shape_filter = ShapeFilter.SelectedShapestask.execute()Tasks
SnapToGridTask
Snaps shape vertices to the nearest grid point.
from linkcad.v1.db import Transactionfrom linkcad.v1.edit import PolygonSnapMode, SnapToGridTask
with Transaction(drawing, "Snap to grid"): SnapToGridTask(drawing, 100, PolygonSnapMode.AllAngle).execute()| Parameter | Type | Default | Description |
|---|---|---|---|
drawing | Drawing | required | Target drawing |
grid | int | required | Grid spacing in database units |
snap_mode | PolygonSnapMode | AllAngle | Whether to force Manhattan geometry |
FlattenTask
Flattens the cell hierarchy below a cell — expands all cell references into that cell. Note that it takes the starting cell, not the drawing.
from linkcad.v1.edit import FlattenTask
FlattenTask(drawing.main_cell).execute()| Parameter | Type | Description |
|---|---|---|
start_cell | Cell | Cell whose references are expanded |
RemoveDuplicatesTask
Removes polygons and polylines with identical geometry.
from linkcad.v1.edit import RemoveDuplicatesTask
RemoveDuplicatesTask(drawing).execute()MergeTask
Merges overlapping polygons on each layer using a boolean union. Curved shapes are tessellated first using the provided Resolution.
from linkcad.v1.edit import EdgePolicy, FillRule, HolesMode, MergeTaskfrom linkcad.v1.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 | Default | Description |
|---|---|---|---|
drawing | Drawing | required | Target drawing |
resolution | Resolution | required | Curve tessellation settings |
fill_rule | FillRule | required | Winding rule for determining polygon interior |
holes_mode | HolesMode | required | How to represent holes in output polygons |
edge_policy | EdgePolicy | required | How to handle inner boundaries |
dont_explode | bool | False | If True, do not decompose complex result polygons |
process_vertically | bool | False | If True, process cells bottom-up (for hierarchical drawings) |
ClosePolylinesTask
Closes open polylines by connecting first and last vertices.
from linkcad.v1.edit import ClosePolylinesTask
ClosePolylinesTask(drawing).execute()JoinPolylinesTask
Joins polylines whose endpoints touch, within tolerance.
from linkcad.v1.edit import JoinPolylinesTask
task = JoinPolylinesTask(drawing, wire_end_tolerance=10, width_tolerance=1)task.execute()print(task.unique_object_count, task.total_object_count)| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
wire_end_tolerance | int | Maximum endpoint gap, in database units |
width_tolerance | int | Maximum width difference between joined polylines |
PolylineToPolygonTask
Converts closed polylines to filled polygons.
from linkcad.v1.edit import PolylineToPolygonTaskfrom linkcad.v1.geom import Resolution
PolylineToPolygonTask(drawing, tolerance=0, resolution=Resolution()).execute()| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
tolerance | int | Endpoint gap still treated as closed |
resolution | Resolution | Curve tessellation settings |
ExplodeToPolygonTask
Converts complex shapes to plain polygons and polylines by tessellation.
from linkcad.v1.edit import ExplodeToPolygonTask, FillRule, HolesMode, ShapesToConvertfrom linkcad.v1.geom import Resolution
res = Resolution()res.minimum_facets = 32
task = ExplodeToPolygonTask( drawing, res, FillRule.NonZero, HolesMode.Link, ShapesToConvert.All)task.execute()print(task.unique_object_count, task.total_object_count)| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
resolution | Resolution | Curve tessellation settings |
fill_rule | FillRule | Winding rule |
holes_mode | HolesMode | How to represent holes |
shapes_to_convert | ShapesToConvert | Which shape types to explode |
unique_object_count and total_object_count are properties, and are only defined on the two tasks that count anything: ExplodeToPolygonTask and JoinPolylinesTask.
RemoveZeroWidthPolylinesTask
Deletes all polylines with a width of zero.
from linkcad.v1.edit import RemoveZeroWidthPolylinesTask
RemoveZeroWidthPolylinesTask(drawing).execute()RemoveOverlappingPolylinesTask
Removes polyline segments that overlap other segments on the same layer.
from linkcad.v1.edit import RemoveOverlappingPolylinesTask
RemoveOverlappingPolylinesTask(drawing).execute()FixSelfIntersectingPolygonsTask
Splits self-intersecting polygons into simple polygons.
from linkcad.v1.edit import FillRule, FixSelfIntersectingPolygonsTask, HolesMode
FixSelfIntersectingPolygonsTask(drawing, FillRule.NonZero, HolesMode.Link).execute()| Parameter | Type | Description |
|---|---|---|
drawing | Drawing | Target drawing |
fill_rule | FillRule | Winding rule |
holes_mode | HolesMode | How to represent holes |
Enums
FillRule
Winding rule used when determining which regions are “inside” a polygon. Re-exported from linkcad.v1.db.
| Value | Description |
|---|---|
FillRule.NonZero | Non-zero winding rule (standard CAD/EDA convention) |
FillRule.EvenOdd | Even-odd (alternating fill) rule |
HolesMode
Controls how holes in result polygons are represented. Re-exported from linkcad.v1.plugin.
| Value | Description |
|---|---|
HolesMode.Link | Link holes to the outer boundary with zero-width bridges |
HolesMode.Split | Split polygons so no holes appear in output |
HolesMode.Extract | Return holes as separate polygons |
HolesMode.Keep | Keep holes as they are |
EdgePolicy
Controls how inner boundaries are handled during merge.
| Value | Description |
|---|---|
EdgePolicy.Keep | Keep original inner boundaries |
EdgePolicy.Merge | Merge inner boundaries |
PolygonSnapMode
Controls the angles vertices may take after snapping.
| Value | Description |
|---|---|
PolygonSnapMode.AllAngle | Allow all angles |
PolygonSnapMode.ForceManhattan | Force Manhattan (orthogonal) geometry |
ShapesToConvert
Selects which shape types ExplodeToPolygonTask converts. Values combine.
| Value | Description |
|---|---|
ShapesToConvert.None | Nothing |
ShapesToConvert.All | Every convertible shape type |
ShapesToConvert.Polylines | Polylines |
ShapesToConvert.Text | Text |
ShapesToConvert.Circles | Circles and ellipses |
ShapesToConvert.Arcs | Arcs |
ShapesToConvert.Donuts | Donuts |
ShapesToConvert.Nurbs | NURBS curves |
ShapesToConvert.ZeroWidthClosedPolylines | Closed polylines of zero width |
None is a Python keyword, so that member is reachable only as getattr(ShapesToConvert, "None").