Skip to main content

Module cadrefs

Module cadrefs 

Source
Expand description

References inside CAD files: an assembly names its component files, a drawing the model it documents, a STEP file its external parts, a KiCad project its sheets.

The names are found without the CAD programs’ own libraries: TeamCraft scans the file for text – ASCII/UTF-8 and UTF-16 (Windows programs such as SolidWorks, Inventor, Solid Edge and CATIA store paths that way) – that ends with the extension of a CAD file (Bracket.SLDPRT, C:\Rover\Motor mount.ipt, 'nozzle.stp', "power.kicad_sch"). Paths are reduced to the file name. UTF-16 strings with a length prefix (as Inventor stores its references) are also read by their length, so a binary field right after the name cannot hide it. The result is a list of referenced file names; services::references matches them against the files in the vault.

Two containers are read by their structure instead: NX parts (nxpart: only the reference streams) and SOLIDWORKS 2015+ files (swpart: the component tree of an assembly, otherwise the document manager’s section – both inflated from their compressed sections). The rest of such a file (history, old names) is never scanned.

For those two – and for STEP assemblies with external references – the scan also tells how often an assembly places each component (instance_counts, stored as file_references.instances); every other format gives names only.

For every other file this is a heuristic: a name that a CAD program keeps in its file after the component was removed is still found, and compressed sections of unknown containers are not read. The revision page therefore shows the names as “found in the file”.

Structs§

FileRef
A file name referenced by a CAD file, with how often the file places it where its format tells (see instance_counts).

Constants§

EXPORT_NAME_SCAN
Bytes of a STEP file read for its export name: the HEADER comes first.
MAX_SCAN
Bytes scanned per file.

Functions§

find
The CAD file names referenced in content, without own_name; each name once (case-insensitive), in the order found.
instance_counts
How often an assembly places each component file – keyed by the lower case, normalised file name – where its format tells:
scan_export_name
step_export_name of a stored file (its first EXPORT_NAME_SCAN bytes); None if it cannot be read.
scan_file
Reads a stored file and finds its references: NX parts through their stream directory and SOLIDWORKS 2015+ files through their sections (with seeks, so large files are read completely), everything else from its first MAX_SCAN bytes. The instance counts come from instance_counts for the file’s format.
scans
Whether files of this format are scanned for references: assemblies, drawings, multi-purpose models (NX, Fusion, FreeCAD, …), STEP/JT (external references), PLM XML and KiCad projects/schematics.
step_export_name
The name a STEP file was exported under – the first string of the FILE_NAME(...) entity in its HEADER, reduced to the file name – when it is the name of a referencable file and differs from own_name. Other files may reference the file under that name (an assembly exported together with its parts, a part renamed after the export); it is a second name of the file itself and never a reference to another file.
with_counts
The names with their counts: a name the counts do not list is None (not known), as is every name when the file tells no counts.