Table of Contents

CadDataLinks

from OpenCAD2D import CadDataLinks

class CadDataLinks(System.Object) ยท CadDataLinks in the .NET reference

The data links of a drawing, as AutoCAD 2021's DATALINK and DATALINKUPDATE and the table's data link menus work them: a link to a spreadsheet (an .xlsx workbook or a .csv file) made, changed, renamed and deleted, a table's cells linked to it, filled from its source and written back to it. A link is a DATALINK object of the drawing's ACAD_DATALINK dictionary, written as AutoCAD 2021 writes the link of its own Excel adapter (AcExcel): its adapter, tooltip and connection string, its options and update options, when it was last updated, the tables it fills and its custom data (the update options, the connection string and the source file's date), so that AutoCAD opens the drawing and reads the link as its own. A drawing before AutoCAD 2007 (AC1021) has no data links.

Properties and fields

AllowSourceUpdate

.NET

AllowSourceUpdate: ClassVar[int]

The flag of AutoCAD's UpdateOption that lets the link write the table back to its source.

ExtractionAdapter

.NET

ExtractionAdapter: ClassVar[str]

The data adapter of a data extraction's link, as AutoCAD names it.

SkipFormat

.NET

SkipFormat: ClassVar[int]

The flag of AutoCAD's UpdateOption that leaves the workbook's formatting out of the table.

Methods

CanHold

.NET

@staticmethod
def CanHold(document: CadDocument) -> bool

Whether the drawing can hold data links: a drawing of AutoCAD 2007 (AC1021) or later with a dictionary of objects.

Create

.NET

@staticmethod
def Create(document: CadDocument, settings: CadDataLinkSettings) -> CadEditResult

Makes a data link, as the New Excel Data Link dialog does: one undo step. The name has to be new ("Data link name in use."), the source has to read, and the drawing has to be of AutoCAD 2007 or later.

Delete

.NET

@staticmethod
def Delete(document: CadDocument, name: str) -> CadEditResult

Deletes a data link, one undo step. A link that fills a table is in use and is refused, "The data link is being used and cannot be deleted."; detach it from the table first.

Detach

.NET

@staticmethod
def Detach(document: CadDocument, tableHandle: str, row: int, column: int) -> CadEditResult

Takes the data link off a table's cells, as Detach Data Link does: the cells keep what they hold and are no longer linked, one undo step. The link stays in the drawing, in the Data Link Manager.

Edit

.NET

@staticmethod
def Edit(document: CadDocument, name: str, settings: CadDataLinkSettings) -> CadEditResult

Changes a data link, as Modify Excel Link does: its file, cells and options written anew, one undo step. The tables it fills are not changed until the link is updated.

Find

.NET

@staticmethod
def Find(document: CadDocument, name: str) -> DxfDataLink

Finds a link by its name, letters of either case alike.

FolderOf

.NET

@staticmethod
def FolderOf(document: CadDocument) -> str

The folder of the drawing's file; null for a drawing not saved.

LinkCells

.NET

@staticmethod
def LinkCells(document: CadDocument, tableHandle: str, row: int, column: int, linkName: str) -> CadEditResult

Links a table's cells to a data link, as Link Cell does and as a table made from a data link is: the data read from the source and put into the table from the cell given, rows and columns added where the table is too small to hold it, the cells linked, one undo step. A table of a drawing before AutoCAD 2007, or whose cells are linked already, is refused.

List

.NET

@staticmethod
def List(document: CadDocument) -> System.Collections.Generic.IReadOnlyList[CadDataLinkInfo]

The data links of the drawing, by name.

Preview

.NET

@staticmethod
def Preview(document: CadDocument, settings: CadDataLinkSettings) -> CadSheet

Reads what a data link's settings link, for the dialog's preview and for the checks of CadDataLinks.Create.

RelativePath

.NET

@staticmethod
def RelativePath(folder: str, file: str) -> str

The path from a folder to a file, ..\data\parts.xlsx; the file's full path where it is on another drive.

Rename

.NET

@staticmethod
def Rename(document: CadDocument, name: str, newName: str) -> CadEditResult

Renames a data link, one undo step.

Update

.NET

@staticmethod
def Update(document: CadDocument, links: System.Collections.Generic.IEnumerable[DxfDataLink]) -> CadDataLinkRun

Updates data links from their sources, as DATALINKUPDATE's Update data link does: each link's source read, and the cells of each table it fills made what the source holds, rows and columns added or taken out to its size, the link's time and status written; one undo step. A link whose source cannot be read is counted as failed with its message and its tables left as they were.

Write

.NET

@staticmethod
def Write(document: CadDocument, links: System.Collections.Generic.IEnumerable[DxfDataLink]) -> CadDataLinkRun

Writes data links to their sources, as DATALINKUPDATE's Write data link does: the cells of each table a link fills put back into the workbook or the CSV file, whose other cells stay as they are. A link that does not allow it (its update options lack CadDataLinks.AllowSourceUpdate) is counted apart; a source that cannot be written is failed. The status of each link is written, one undo step.