linkcad.conv
File format conversion — loading and saving drawings programmatically.
from linkcad.v1.conv import ( Conversion, Conversions, FormatRegistry, FormatInfo, Format, FormatAttributes,)Classes
Conversions
The batch container, and the way to obtain a Conversion. A Conversion is never constructed directly — ask a Conversions collection for one.
from linkcad.v1.conv import Conversions
batch = Conversions()conv = batch.append_new("GDSII", "DXF")conv.import_paths = ["/data/design.gds"]conv.export_path = "/data/design.dxf"
conv.read_file()if not conv.succeeded: raise RuntimeError("Import failed")
dwg = conv.drawing# optionally inspect/modify dwg under WriteLock here
conv.write_file()if not conv.succeeded: raise RuntimeError("Export failed")| Property / Method | Description |
|---|---|
Conversions() | Create an empty collection |
batch.append_new(import_format, export_format) | Append a new Conversion and return it |
batch.start() / batch.next() | Move the cursor to the first / next conversion |
batch.done | True once the cursor has run past the last conversion |
batch.current | The conversion under the cursor; raises once done |
len(batch) | Number of conversions |
batch.position | Index of the current conversion (0-based) |
batch.clear() | Remove all conversions |
batch.has_duplicate_file_titles | Whether two jobs would write the same file title |
batch.owner_window | Owner window ID, for modal progress dialogs; assignable |
Iterating a batch:
batch.start()while not batch.done: conv = batch.current conv.read_file() conv.write_file() batch.next()Conversion
A single import → export operation.
| Property / Method | Description |
|---|---|
conv.import_format | Import format name (e.g. "GDSII"); assignable |
conv.import_format_extension / conv.import_format_attributes | Import format metadata |
conv.import_paths | Input file paths, as a list of strings; assignable |
conv.export_path | Output file path, as a string; assignable, and accepts any os.PathLike |
conv.create_export_path() | Derive the output path from the input path |
conv.export_format / conv.export_format_extension / conv.export_format_attributes | Export format metadata |
conv.read_file() | Execute the import step |
conv.write_file() | Execute the export step |
conv.drawing | The Drawing produced by read_file(), or None |
conv.delete_drawing() | Release the drawing’s memory |
conv.succeeded | True if the last operation succeeded |
conv.progress | Progress percentage (0-100) |
conv.cancel() / conv.cancelled | Cancel, and test for cancellation |
conv.import_log | Import log, as an IEventLogReader |
conv.export_log | Export log, as an IEventLog |
The export format is fixed when the conversion is created, so export_format is read-only — pass it to append_new().
FormatRegistry
The singleton registry of formats LinkCAD can read and write.
from linkcad.v1.conv import FormatRegistry
registry = FormatRegistry.get_instance()for info in registry.import_formats: file_filter, display_name = registry.import_format_filter(info.plugin_name) print(f"{display_name}: {file_filter}")| Property / Method | Description |
|---|---|
FormatRegistry.get_instance() | Static — get the singleton registry |
registry.import_formats / registry.export_formats | A FormatInfo for every registered format |
registry.import_format(plugin_name) / registry.export_format(plugin_name) | The format’s Format constraints, or None |
registry.import_format_filter(plugin_name) / registry.export_format_filter(plugin_name) | (file_filter, display_name) tuple |
registry.default_extension(plugin_name) | Default file extension |
registry.import_format_licensed(plugin_name) / registry.export_format_licensed(plugin_name) | Licensing check |
registry.plugin_name_from_id(id) | Resolve a numeric format ID |
The licence manager is installed by the host application before any script runs, so get_instance() takes no argument.
FormatInfo
Returned where the registry describes a format entry.
| Property | Description |
|---|---|
info.id | Unique format ID |
info.plugin_name | Plugin name (e.g. "GDSII") |
info.display_name | Human-readable display name |
info.licensed | Whether the format is licensed |
Format
The validation constraints a file format imposes on layer and cell names. Format plugins construct one to declare what they support; FormatRegistry.import_format() returns the constraints of a built-in format.
from linkcad.v1.conv import Format, FormatAttributes
fmt = Format()fmt.attributes = FormatAttributes.LAYER_NUMBERS | FormatAttributes.LAYER_NAMESfmt.set_layer_number_range(0, 255)fmt.layer_max_length = 32| Property / Method | Description |
|---|---|
Format() | Create a format descriptor with default attributes |
fmt.attributes | Format capability flags; assignable |
fmt.layer_max_length / fmt.cell_max_length | Maximum name lengths; assignable |
fmt.set_layer_number_range(min, max=-1) | Set valid layer-number range |
fmt.set_valid_layer_chars(char_set, initial_chars=None, preferred_prefix=None) | Set valid layer-name characters |
fmt.set_cell_number_range(min, max=-1) | Set valid cell-number range |
fmt.set_valid_cell_chars(char_set, initial_chars=None, preferred_prefix=None) | Set valid cell-name characters |
fmt.set_file_name_extension(ext) | Set cell file-name extension |
fmt.layer_min_number / fmt.layer_max_number | Current layer-number range |
fmt.cell_min_number / fmt.cell_max_number | Current cell-number range |
fmt.layer_char_set / fmt.cell_char_set | Current valid-character sets |
fmt.is_valid_layer_name(layer_name, auto_uppercase=False) | Validate one layer name |
fmt.is_valid_cell_name(cell_name, auto_uppercase=False) | Validate one cell name |
fmt.validate_layers(drawing, copy_from_input=True, allow_duplicates=False) | Validate layers in a drawing |
fmt.validate_cells(drawing, copy_from_input=True) | Validate cells in a drawing |
set_layer_number_range() and set_cell_number_range() stay methods: a setter that takes several values at once cannot be an assignment.
FormatAttributes
Bit-flag constants for format capabilities. Combine them with | and assign the result to Format.attributes.
| Constant | Meaning |
|---|---|
FormatAttributes.NONE | No special attributes |
FormatAttributes.LAYER_NUMBERS | Format supports layer numbers |
FormatAttributes.LAYER_NAMES | Format supports layer names |
FormatAttributes.LAYER_FILE_NAMES | Format stores layer names as file names |
FormatAttributes.LAYER_COMMENTS | Format supports layer comments |
FormatAttributes.LAYER_COLORS | Format supports layer colors |
FormatAttributes.LAYER_ELEVATION | Format supports layer elevation/Z values |
FormatAttributes.LAYER_FLASHED_RECTS | Format supports flashed rectangles |
FormatAttributes.LAYER_FLASHED_CIRCLES | Format supports flashed circles |
FormatAttributes.LAYER_FILLED_POLYGONS | Format supports filled polygons |
FormatAttributes.LAYER_OUTLINED_POLYS | Format supports outlined polygons |
FormatAttributes.LAYER_POLARITY | Format supports layer polarity |
FormatAttributes.CELL_NUMBERS | Format supports cell numbers |
FormatAttributes.CELL_NAMES | Format supports cell names |
FormatAttributes.CELL_FILE_NAMES | Format stores cell names as file names |
FormatAttributes.CELL_NAMES_IGNORE_CASE | Cell-name matching ignores case |
FormatAttributes.SUPPORT_BULGE_POLYGONS | Format supports bulge polygons |
FormatAttributes.MULTIPLE_FILES | Format can read or write multiple files |
FormatAttributes.SINGLE_PASS | Format can run in a single pass |
FormatAttributes.DIRECTORY_OUTPUT | Format writes a directory |
FormatAttributes.DIRECTORY_INPUT | Format reads a directory |
FormatAttributes.SOURCE_INSPECTION | Format supports source inspection metadata |