Skip to content

linkcad.conv

File format conversion — loading and saving drawings programmatically.

from linkcad.v1.conv import Conversion, Conversions, FormatRegistry, Format, FormatAttributes

Classes

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")
MethodDescription
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()
MethodDescription
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)
MethodDescription
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.

PropertyDescription
fmt.nameFormat display name (e.g. "GDSII")
fmt.extensionsList of file patterns (e.g. ["*.gds", "*.gdsii"])
fmt.can_readTrue if the format supports import
fmt.can_writeTrue 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)
MethodDescription
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().

ConstantMeaning
FormatAttributes.NONENo special attributes
FormatAttributes.LAYER_NUMBERSFormat supports layer numbers
FormatAttributes.LAYER_NAMESFormat supports layer names
FormatAttributes.LAYER_FILE_NAMESFormat stores layer names as file names
FormatAttributes.LAYER_COMMENTSFormat supports layer comments
FormatAttributes.LAYER_COLORSFormat supports layer colors
FormatAttributes.LAYER_ELEVATIONFormat supports layer elevation/Z values
FormatAttributes.LAYER_FLASHED_RECTSFormat supports flashed rectangles
FormatAttributes.LAYER_FLASHED_CIRCLESFormat supports flashed circles
FormatAttributes.LAYER_FILLED_POLYGONSFormat supports filled polygons
FormatAttributes.LAYER_OUTLINED_POLYSFormat supports outlined polygons
FormatAttributes.LAYER_POLARITYFormat supports layer polarity
FormatAttributes.CELL_NUMBERSFormat supports cell numbers
FormatAttributes.CELL_NAMESFormat supports cell names
FormatAttributes.CELL_FILE_NAMESFormat stores cell names as file names
FormatAttributes.CELL_NAMES_IGNORE_CASECell-name matching ignores case
FormatAttributes.SUPPORT_BULGE_POLYGONSFormat supports bulge polygons
FormatAttributes.MULTIPLE_FILESFormat can read or write multiple files
FormatAttributes.SINGLE_PASSFormat can run in a single pass
FormatAttributes.DIRECTORY_OUTPUTFormat writes a directory
FormatAttributes.DIRECTORY_INPUTFormat reads a directory
FormatAttributes.SOURCE_INSPECTIONFormat supports source inspection metadata