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.
#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()))