Demonstrates reading the open PCB layout: board title, placed component and copper network overview, breakdown of geometry, layer stack, design rule check results, and the linked schematic 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<Board> board = product->cast<Board>();
if (!board)
{
app->log("Active product is not a board.");
return false;
}
app->log("Board: " + board->name());
app->log(" headline: " + board->headline());
app->log(
" elements: " + std::to_string(board->elements()->count()) + " copper networks: " +
std::to_string(board->signals()->count()) + " layers: " + std::to_string(board->layers()->count()));
Ptr<Signals> sigs = board->signals();
app->log(" per copper network:");
for (size_t i = 0; i < sigs->count(); ++i)
{
Ptr<Signal> sig = sigs->item(i);
const size_t traces = sig->wires()->count();
const size_t pours = sig->polyPours()->count();
const size_t v = sig->vias()->count();
const size_t contacts = sig->contactRefs()->count();
const size_t tot = traces + pours + v + contacts;
app->log(" " + sig->name());
app->log(
" traces=" + std::to_string(traces) + " pours=" + std::to_string(pours) +
" vias=" + std::to_string(v) + " contacts=" + std::to_string(contacts) + " total=" + std::to_string(tot));
}
Ptr<Layers> lays = board->layers();
app->log(" per layer:");
for (size_t i = 0; i < lays->count(); ++i)
{
Ptr<Layer> ly = lays->item(i);
app->log(
" [" + std::to_string(ly->number()) + "] " + ly->name() + " used=" +
std::string(ly->used() ? "True" : "False") + " visible=" + std::string(ly->visible() ? "True" : "False"));
}
app->log(" design rule check errors: " + std::to_string(board->errors()->count()));
Ptr<Schematic> sch = board->linkedSchematic();
if (sch)
app->log(" linked schematic: " + sch->name());
return true;
}
# For this sample script to run, the active Fusion document must have an electronics PCB layout as the active product.
import adsk.core, adsk.electron, traceback
def run(context):
app = adsk.core.Application.get()
try:
board = adsk.electron.Board.cast(app.activeProduct)
if not board:
app.log("Active product is not a board.")
return
app.log("Board: {}".format(board.name))
app.log(" headline: {}".format(board.headline))
app.log(" components: {} copper networks: {} layers: {}".format(
board.elements.count, board.signals.count, board.layers.count))
sigs = board.signals
app.log(" per copper network:")
for i in range(sigs.count):
sig = sigs.item(i)
traces = sig.wires.count
pours = sig.polyPours.count
v = sig.vias.count
contacts = sig.contactRefs.count
tot = traces + pours + v + contacts
app.log(" {}".format(sig.name))
app.log(
" traces={} pours={} vias={} contacts={} total={}".format(
traces, pours, v, contacts, tot))
lays = board.layers
app.log(" per layer:")
for i in range(lays.count):
ly = lays.item(i)
app.log(" [{}] {} used={} visible={}".format(
ly.number, ly.name, ly.used, ly.visible))
app.log(" design rule check errors: {}".format(board.errors.count))
sch = board.linkedSchematic
if sch:
app.log(" linked schematic: {}".format(sch.name))
except Exception:
app.log("Failed:\n{}".format(traceback.format_exc()))