Demonstrates reading the open electronics schematic: document title, sheet and connectivity overview, per-sheet component and geometry counts, electrical rule check results, and the linked PCB when the design includes one.
/** * Electronics Schematic Summary Sample * Demonstrates reading the open electronics schematic: document title, sheet and connectivity overview, per-sheet component and geometry counts, electrical rule check results, and the linked PCB when the design includes one. * * For this sample script to run, the active Fusion document must have an electronics schematic as the active product. */ import { adsk } from '@adsk/fusion'; /** NIDL exposes this as `number`, but TypeScript codegen skips the reserved keyword. */ function ecadNumber(obj: adsk.electron.Layer | adsk.electron.Sheet): number { return (obj as unknown as { number: number }).number; } function run(): void { const app = adsk.core.Application.get(); if (!app) throw new Error('No adsk.core.Application.'); try { const product = app.activeProduct; if (!product) { adsk.log('No active product.'); return; } const schematic = product as unknown as adsk.electron.Schematic; adsk.log('Schematic: ' + schematic.name); adsk.log(' headline: ' + schematic.headline); const sheets = schematic.sheets; adsk.log( ' sheets: ' + sheets.count + ' parts: ' + schematic.parts.count + ' nets: ' + schematic.nets.count, ); adsk.log(' per sheet:'); for (let i = 0; i < sheets.count; i++) { const sh = sheets.item(i); if (!sh) continue; adsk.log(' [' + ecadNumber(sh) + '] ' + sh.name + ' - ' + sh.headline); const inst = sh.instances.count; const w = sh.wires.count; const nt = sh.nets.count; const tx = sh.texts.count; let tot = inst + w + nt + tx; tot += sh.circles.count; tot += sh.rectangles.count; tot += sh.polyShapes.count; tot += sh.busses.count; tot += sh.moduleInstances.count; tot += sh.frames.count; tot += sh.dimensions.count; adsk.log( ' instances=' + inst + ' wires=' + w + ' nets=' + nt + ' texts=' + tx + ' total=' + tot, ); } adsk.log(' electrical rule check errors: ' + schematic.errors.count); const board = schematic.linkedBoard; if (board) { adsk.log(' linked board: ' + board.name); } } catch (err) { adsk.log('Failed:\n' + String(err)); } } run();
#include <Core/CoreAll.h>
#include <Electron/ElectronAll.h>
#include <string>
using namespace adsk::core;
using namespace adsk::electron;
extern "C" XI_EXPORT bool run(const char* context)
{
Ptr<Application> app = Application::get();
if (!app)
return false;
Ptr<Product> product = app->activeProduct();
if (!product)
{
app->log("No active product.");
return false;
}
Ptr<Schematic> schematic = product->cast<Schematic>();
if (!schematic)
{
app->log("Active product is not a schematic.");
return false;
}
app->log("Schematic: " + schematic->name());
app->log(" headline: " + schematic->headline());
Ptr<Sheets> sheets = schematic->sheets();
app->log(
" sheets: " + std::to_string(sheets->count()) + " parts: " + std::to_string(schematic->parts()->count()) +
" nets: " + std::to_string(schematic->nets()->count()));
app->log(" per sheet:");
for (size_t i = 0; i < sheets->count(); ++i)
{
Ptr<Sheet> sh = sheets->item(i);
app->log(" [" + std::to_string(sh->number()) + "] " + sh->name() + " - " + sh->headline());
const size_t inst = sh->instances()->count();
const size_t w = sh->wires()->count();
const size_t nt = sh->nets()->count();
const size_t tx = sh->texts()->count();
size_t tot = inst + w + nt + tx;
tot += sh->circles()->count();
tot += sh->rectangles()->count();
tot += sh->polyShapes()->count();
tot += sh->busses()->count();
tot += sh->moduleInstances()->count();
tot += sh->frames()->count();
tot += sh->dimensions()->count();
app->log(
" instances=" + std::to_string(inst) + " wires=" + std::to_string(w) + " nets=" + std::to_string(nt) +
" texts=" + std::to_string(tx) + " total=" + std::to_string(tot));
}
app->log(" electrical rule check errors: " + std::to_string(schematic->errors()->count()));
Ptr<Board> board = schematic->linkedBoard();
if (board)
app->log(" linked board: " + board->name());
return true;
}
# For this sample script to run, the active Fusion document must have an electronics schematic as the active product.
import adsk.core, adsk.electron, traceback
def run(context):
app = adsk.core.Application.get()
try:
schematic = adsk.electron.Schematic.cast(app.activeProduct)
if not schematic:
app.log("Active product is not a schematic.")
return
app.log("Schematic: {}".format(schematic.name))
app.log(" headline: {}".format(schematic.headline))
sheets = schematic.sheets
app.log(" sheets: {} parts: {} nets: {}".format(
sheets.count, schematic.parts.count, schematic.nets.count))
app.log(" per sheet:")
for i in range(sheets.count):
sh = sheets.item(i)
app.log(' [{}] {} - {}'.format(sh.number, sh.name, sh.headline))
inst = sh.instances.count
w = sh.wires.count
nt = sh.nets.count
tx = sh.texts.count
tot = inst + w + nt + tx
tot += sh.circles.count
tot += sh.rectangles.count
tot += sh.polyShapes.count
tot += sh.busses.count
tot += sh.moduleInstances.count
tot += sh.frames.count
tot += sh.dimensions.count
app.log(
" instances={} wires={} nets={} texts={} total={}".format(
inst, w, nt, tx, tot))
app.log(" electrical rule check errors: {}".format(schematic.errors.count))
board = schematic.linkedBoard
if board:
app.log(" linked board: {}".format(board.name))
except Exception:
app.log("Failed:\n{}".format(traceback.format_exc()))