Skip to content

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 / MethodDescription
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.doneTrue once the cursor has run past the last conversion
batch.currentThe conversion under the cursor; raises once done
len(batch)Number of conversions
batch.positionIndex of the current conversion (0-based)
batch.clear()Remove all conversions
batch.has_duplicate_file_titlesWhether two jobs would write the same file title
batch.owner_windowOwner 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 / MethodDescription
conv.import_formatImport format name (e.g. "GDSII"); assignable
conv.import_format_extension / conv.import_format_attributesImport format metadata
conv.import_pathsInput file paths, as a list of strings; assignable
conv.export_pathOutput 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_attributesExport format metadata
conv.read_file()Execute the import step
conv.write_file()Execute the export step
conv.drawingThe Drawing produced by read_file(), or None
conv.delete_drawing()Release the drawing’s memory
conv.succeededTrue if the last operation succeeded
conv.progressProgress percentage (0-100)
conv.cancel() / conv.cancelledCancel, and test for cancellation
conv.import_logImport log, as an IEventLogReader
conv.export_logExport 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 / MethodDescription
FormatRegistry.get_instance()Static — get the singleton registry
registry.import_formats / registry.export_formatsA 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.

PropertyDescription
info.idUnique format ID
info.plugin_namePlugin name (e.g. "GDSII")
info.display_nameHuman-readable display name
info.licensedWhether 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_NAMES
fmt.set_layer_number_range(0, 255)
fmt.layer_max_length = 32
Property / MethodDescription
Format()Create a format descriptor with default attributes
fmt.attributesFormat capability flags; assignable
fmt.layer_max_length / fmt.cell_max_lengthMaximum 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_numberCurrent layer-number range
fmt.cell_min_number / fmt.cell_max_numberCurrent cell-number range
fmt.layer_char_set / fmt.cell_char_setCurrent 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.

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