master
Drew Owens Current base scaffold model (Base Scaffold Assembly v7: 7 mm sheet, 5-hole panels, gold contacts), alignment features,… 598955f
# Export the current base scaffold ('Base Scaffold Assembly', Main) as STEP with real contact panels.
# The assembly's 9 panels are 'BaseSaffoldPanel 5 hole 1.6mm' (bare FR4, no contacts). In memory only,
# this places a local copy of 'Base Scaffold 5 HOLES' (the panel with its 36 contacts) at each panel,
# hides the bare panels, gives the contacts 'Gold - Polished', exports, and closes WITHOUT saving.
# Scaffold only: the workcell-side 'Base Scaffold Rail Panel Assembly' and the old v2.0.1
# control-panel circuit board (own wiki page) are hidden, so they stay out of the STEP.
import os, json, time, traceback
ASM = 'urn:adsk.wipprod:dm.lineage:0KMYcZqHRFa0uKDmV7QO8Q'
PANEL5 = 'urn:adsk.wipprod:dm.lineage:qYUGHjbdRKGe-Dwb6BSu6Q'
outdir = os.path.join(os.path.expanduser('~'), 'Downloads', 'adom-scaffold-panel')
os.makedirs(outdir, exist_ok=True)
rep = {'activeBefore': app.activeDocument.name if app.activeDocument else None}
t0 = time.time(); doc = None
def colors_of(ap):
    out = None
    try:
        for i in range(ap.appearanceProperties.count):
            p = ap.appearanceProperties.item(i)
            if isinstance(p, adsk.core.ColorProperty) and p.value:
                c = p.value; out = [c.red, c.green, c.blue, c.opacity]; break
    except Exception: pass
    return out
try:
    adf = app.data.findFileById(ASM)
    rep['assembly'] = [adf.name, adf.versionNumber]
    doc = app.documents.open(adf, False)
    des = adsk.fusion.Design.cast(doc.products.itemByProductType('DesignProductType'))
    root = des.rootComponent
    bare = [o for o in root.allOccurrences if o.component.name == 'BaseSaffoldPanel 5 hole 1.6mm']
    rep['barePanels'] = len(bare)
    pdf = app.data.findFileById(PANEL5)
    rep['panel'] = [pdf.name, pdf.versionNumber]
    placed = []
    first = None
    for o in bare:
        bb = o.boundingBox  # world, cm; bare panel local x/y 0.019..19.181 cm, z -0.001..0.161
        m = adsk.core.Matrix3D.create()
        m.translation = adsk.core.Vector3D.create(bb.minPoint.x - 0.019 + 1.6, bb.minPoint.y - 0.019 + 1.6, bb.minPoint.z + 0.001)
        if first is None:
            first = root.occurrences.addByInsert(pdf, m, False)
            new = first
        else:
            new = root.occurrences.addExistingComponent(first.component, m)
        placed.append([round(bb.minPoint.x*10,2), round(bb.minPoint.y*10,2), round(bb.minPoint.z*10,2)])
    rep['placedAtBareMinMm'] = placed
    hid = 0; hideErr = None
    for o in bare:
        try:
            o.isLightBulbOn = False; hid += 1
        except Exception as e:
            hideErr = str(e)
    rep['hidden'] = hid; rep['hideErr'] = hideErr
    skipped = []
    for o in list(root.occurrences) + list(root.allOccurrences):
        if o.component.name.startswith('Base Scaffold Rail Panel Assembly') or o.component.name.startswith('OLD_control-panel'):
            if o.isLightBulbOn:
                o.isLightBulbOn = False; skipped.append(o.fullPathName)
    rep['hiddenForScaffoldOnly'] = skipped
    gold_lib = app.materialLibraries.itemByName('Fusion Appearance Library').appearances.itemByName('Gold - Polished')
    gold = des.appearances.itemByName('Gold - Polished') or des.appearances.addByCopy(gold_lib, 'Gold - Polished')
    n = 0
    for o in first.component.allOccurrences:
        if o.component.name == 'MpinContact_Large v1':
            for b in o.component.bRepBodies:
                b.appearance = gold; n += 1
    rep['contactBodiesGold'] = n
    # 'ABS (White)' exports to STEP as black (its first color property is black), so give those
    # occurrences a white plastic from the library for the export only.
    applib = app.materialLibraries.itemByName('Fusion Appearance Library').appearances
    white_lib = None
    for nm in ('Plastic - Matte (White)', 'Plastic - Glossy (White)', 'Plastic - Translucent Matte (White)'):
        white_lib = applib.itemByName(nm)
        if white_lib: break
    white = des.appearances.itemByName(white_lib.name) or des.appearances.addByCopy(white_lib, white_lib.name)
    absfix = []
    for o in root.allOccurrences:
        if not o.isVisible: continue
        bodies = [b for b in o.bRepBodies if b.isVisible and b.appearance and b.appearance.name == 'ABS (White)']
        if bodies:
            try:
                o.appearance = white; absfix.append([o.fullPathName, 'occurrence'])
            except Exception as e:
                for b in bodies:
                    try: b.appearance = white; absfix.append([o.fullPathName, 'body'])
                    except Exception as e2: absfix.append([o.fullPathName, 'FAILED ' + str(e2)[:60]])
    rep['absWhiteFix'] = {'appearance': white.name, 'parts': absfix}
    # appearance inventory of everything visible (for the GLB material pass)
    aps = {}
    def visit(comp, occ_visible=True):
        pass
    for b in list(root.bRepBodies):
        if b.isVisible and b.appearance: aps.setdefault(b.appearance.name, colors_of(b.appearance))
    for o in root.allOccurrences:
        if not o.isVisible: continue
        for b in o.bRepBodies:
            if b.isVisible:
                ap = b.appearance
                if ap: aps.setdefault(ap.name, colors_of(ap))
    rep['appearances'] = aps
    bb = root.boundingBox
    rep['bboxMm'] = [round(v*10,1) for v in (bb.minPoint.x,bb.minPoint.y,bb.minPoint.z,bb.maxPoint.x,bb.maxPoint.y,bb.maxPoint.z)]
    em = des.exportManager
    step_path = os.path.join(outdir, 'base-scaffold-v%d.step' % adf.versionNumber)
    rep['stepOk'] = em.execute(em.createSTEPExportOptions(step_path, root))
    rep['stepBytes'] = os.path.getsize(step_path) if os.path.exists(step_path) else None
    rep['stepPath'] = step_path
except Exception:
    rep['error'] = traceback.format_exc()
finally:
    if doc is not None:
        try: doc.close(False); rep['closed'] = True
        except Exception as e: rep['closeError'] = str(e)
rep['activeAfter'] = app.activeDocument.name if app.activeDocument else None
rep['totalSec'] = round(time.time() - t0, 1)
json.dump(rep, open(os.path.join(outdir, 'scaffold-export-report.json'), 'w'), indent=1)
result = rep