linkcad.conv
File format conversion — loading and saving drawings programmatically.
from linkcad.v1.conv import Conversion, Conversions, FormatRegistry, Format, FormatAttributesClasses
Conversion
A single import → export operation. Use this for straightforward one-file conversions.
from linkcad.v1.conv import Conversion
conv = Conversion("GDSII", "DXF")conv.set_import_path("/data/design.gds")conv.set_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")| Method | Description |
|---|---|
Conversion(import_format, export_format) | Construct with format names (e.g. "GDSII", "DXF") |
conv.set_import_path(path) | Set single input file path |
conv.set_export_path(path) | Set output file path |
conv.read_file() | Execute the import step |
conv.write_file() | Execute the export step |
conv.succeeded() | Returns True if the last operation succeeded |
conv.drawing() | Returns the Drawing produced by read_file() |
Conversions
A batch container for running multiple Conversion jobs. Each job is independent.
from linkcad.v1.conv import Conversions
batch = Conversions()conv = batch.append_new("CIF", "CIF")conv.set_import_paths(["/data/a.cif", "/data/b.cif"])conv.set_export_path("/data/out.cif")
conv.read_file()conv.write_file()| Method | Description |
|---|---|
Conversions() | Create an empty batch |
batch.append_new(import_fmt, export_fmt) | Add a new Conversion to the batch and return it |
conv.set_import_paths(paths) | Set a list of input file paths (for multi-file formats) |
FormatRegistry
Provides access to the list of formats that LinkCAD can read and write.
from linkcad.v1.conv import FormatRegistry
registry = FormatRegistry.instance()for fmt in registry.formats(): print(fmt.name, fmt.extensions)| Method | Description |
|---|---|
FormatRegistry.instance() | Class method — get the singleton registry |
registry.formats() | Iterate all registered Format objects |
registry.find(name) | Find a format by name; returns None if not found |
Format
Describes a single file format supported by LinkCAD. Format also exposes the validation constraints used by format plugins and converters.
| Property | Description |
|---|---|
fmt.name | Format display name (e.g. "GDSII") |
fmt.extensions | List of file patterns (e.g. ["*.gds", "*.gdsii"]) |
fmt.can_read | True if the format supports import |
fmt.can_write | True if the format supports export |
from linkcad.v1.conv import Format, FormatAttributes
fmt = Format()fmt.set_attributes(FormatAttributes.LAYER_NUMBERS | FormatAttributes.LAYER_NAMES)fmt.set_layer_number_range(0, 255)fmt.set_layer_name_length(32)| Method | Description |
|---|---|
Format() | Create a format descriptor with default attributes |
fmt.flags() | Return the current attribute flags |
fmt.set_attributes(attributes) | Set format capability flags |
fmt.set_layer_number_range(min, max=-1) | Set valid layer-number range |
fmt.set_layer_name_length(length) | Set maximum layer-name length |
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_cell_name_length(length) | Set maximum cell-name length |
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.layer_max_length() / fmt.layer_char_set() | Current layer-name constraints |
fmt.cell_min_number() / fmt.cell_max_number() | Current cell-number range |
fmt.cell_max_length() / fmt.cell_char_set() | Current cell-name constraints |
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 |
FormatAttributes
Bit-flag constants for format capabilities. Combine them with | and pass the result to Format.set_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 |