跳转到内容

Entity Wrappers

此内容尚不支持你的语言。

lc_plugin::entity contains read-only wrappers for geometry, layers, and cells passed to export plugins. Writer entity callbacks receive these types when WriterController::render_cell() or WriterController::render_cell_in_layer_order() renders drawing content.

The Python database API exposes equivalent geometry objects in linkcad.v1.db, with additional direct database creation and mutation methods for scripting.

Purpose

Entity wrappers provide safe, typed access to host-owned drawing objects during export. They are lightweight views over native LinkCAD objects. Plugin code should read values from them and write output data; it should not store them beyond the callback that provided them.

Geometry Types

Polygon

MethodDescription
vertex_count() -> usizeNumber of polygon vertices.
vertices() -> Vec<Point>Polygon vertices in database units.
is_box() -> boolWhether the polygon is a rectangular box.
has_bulges() -> boolWhether any edge has a bulge value.
bulges() -> Vec<f64>Per-edge bulge values, or an empty vector.
layer() -> LayerOwning layer.

Polyline

MethodDescription
vertex_count() -> usizeNumber of path vertices.
vertices() -> Vec<Point>Path vertices in database units.
width() -> CoordPath width.
is_closed() -> boolWhether the path is closed.
layer() -> LayerOwning layer.

Arc

MethodDescription
center() -> PointArc center.
radius() -> CoordRadius.
width() -> CoordStroke width.
start_angle() -> AngleStart angle.
end_angle() -> AngleEnd angle.
layer() -> LayerOwning layer.

Ellipse

MethodDescription
center() -> PointCenter point.
diameter() -> CoordDiameter.
layer() -> LayerOwning layer.

Donut

MethodDescription
center() -> PointCenter point.
mean_diameter() -> CoordMean diameter of the annulus.
width() -> CoordRing width.
layer() -> LayerOwning layer.

Text

MethodDescription
position() -> PointText position.
height() -> f64Text height.
width_factor() -> f64Horizontal scale factor.
text() -> StringText content.
font() -> StringFont name.
rotation() -> AngleText rotation.
mirrored_in_x() -> boolWhether text is mirrored in X.
mirrored_in_y() -> boolWhether text is mirrored in Y.
layer() -> LayerOwning layer.
real_property(name: &str) -> Option<f64>Read a real-valued text property.
bool_property(name: &str) -> Option<bool>Read a boolean text property.

Nurbs

MethodDescription
degree() -> i32Curve degree.
width() -> CoordStroke width.
knots() -> Vec<f64>Knot vector.
ctrl_points() -> Vec<Point>Control points.
is_rational() -> boolWhether weights are present.
weights() -> Vec<f64>Weight vector, or an empty vector for non-rational curves.
is_periodic() -> boolWhether the curve is periodic.
layer() -> LayerOwning layer.

Ref

MethodDescription
cell_name() -> StringReferenced cell name.
transformation() -> XformReference transform.
columns() -> i32Reference-array column count.
rows() -> i32Reference-array row count.
column_spacing() -> CoordReference-array column spacing.
row_spacing() -> CoordReference-array row spacing.
layer() -> LayerOwning layer.

Layer and Cell Types

Layer

MethodDescription
name() -> StringLayer name.
color() -> ColorDisplay color.
enabled() -> boolWhether the layer is enabled.

Layer properties that require drawing context, such as polarity group, comment, and export number, are available on WriterController.

Cell

MethodDescription
name() -> StringCell name.

Writer Callback Example

impl Writer for ExampleWriter {
fn write_file(&mut self, _path: &str, ctrl: &mut WriterController) -> bool {
let Some(cell) = ctrl.main_cell() else {
ctrl.log().error("No main cell to export");
return false;
};
ctrl.start_enum_layers(SortOrder::Regular);
while let Some(layer) = ctrl.next_layer() {
let xform = ctrl.transformation(false);
ctrl.render_cell(&cell, &layer, &xform);
}
true
}
fn write_polygon(&mut self, polygon: &Polygon, fill_rule: FillRule) -> bool {
let vertices = polygon.vertices();
let layer_name = polygon.layer().name();
// Write vertices and layer_name to the output format.
let _ = (vertices, layer_name, fill_rule);
true
}
}

Units and Geometry Primitives

Entity methods return lc_types values such as Point, Angle, Color, Xform, Coord, and Resolution. Coordinates and distances are in LinkCAD database units; convert file-format units at the import/export boundary.