跳转到内容

Rust API Reference

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

The Rust plugin API is centered on lc-plugin, with geometry primitives from lc-types. Most plugins can import common symbols through lc_plugin::prelude::*; larger plugins may prefer explicit module imports.

Use the module pages below for practical signatures, method groups, examples, and links to equivalent Python APIs.

Module Overview

AreaModule or TypeUse it for
Plugin traits and registrationReader, Writer, FormatDescriptor, registration macrosImplement import/export behavior, format metadata, and the native GetPlugIn entry point.
Format metadatalc_plugin::formatSet format attributes, file extensions, layer rules, and cell rules.
Import drawing constructionlc_plugin::builder::DrawingBuilderCreate cells, layers, shapes, references, text, progress, and import logs.
Export drawing accesslc_plugin::writer_ctrl::WriterControllerEnumerate layers, cells, fonts, transformations, and rendered geometry.
Entitieslc_plugin::entityRead polygons, polylines, arcs, ellipses, donuts, NURBS, text, references, layers, and cells.
Dialogslc_plugin::dialogDeclare host-rendered import/export option dialogs.
Optionslc_plugin::optionsRegister, read, and write typed plugin options.
Drawing helperslc_plugin::drawingRun post-import drawing operations such as layer boolean and polarity merge.
Logginglc_plugin::logReport informational, warning, and error messages.
Source inspectionlc_plugin::inspectProvide metadata used to populate dynamic import option dialogs.
Geometry and unitslc_typesWork with Point, Angle, Color, Resolution, and transforms.

Import Lifecycle

  1. LinkCAD loads the native plugin library and calls the registration entry point.
  2. LinkCAD requests format metadata through FormatDescriptor::describe_format.
  3. For an import, LinkCAD calls Reader::parse_file with a DrawingBuilder.
  4. The reader creates cells, selects layers, emits entities, logs messages, and returns true on success.
  5. Optional Reader::post_process hooks can run after parsing phases to merge layers or adjust the drawing.

Export Lifecycle

  1. LinkCAD calls Writer::write_file with a WriterController.
  2. The writer configures rendering options, enumerates layers and cells, or lets LinkCAD render cells back through entity callbacks.
  3. Entity callback methods such as write_polygon, write_arc, and write_text receive geometry in host units.
  4. The writer logs diagnostics and returns true when the output file was written successfully.

Naming Conventions

Rust API names use snake_case methods and strongly typed enums. Coordinates and distances use LinkCAD database units through lc_types; convert source file units explicitly at the format boundary.

Python Counterparts

The Rust and Python plugin APIs share the same conceptual model. Use these pages when translating examples between native Rust plugins and embedded Python plugins:

  • linkcad.v1.plugin — reader/writer classes, low-level builder/controller wrappers, dialog metadata, plugin enums.
  • linkcad.v1.db — drawing helpers, geometry entities, database enums, and direct scripting access.
  • linkcad.v1.convFormat and FormatAttributes metadata.
  • linkcad.v1.env — options and event logging.