[Bug] Electronics API Python: SCRIPT ERROR when reading part property
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm converting the Fusion Electronics Bill of Material ULP to Python, so that it has more capabilities (for example, exporting to PDF).
Some components have a footprint, while others have not. Only the parts with footprint should be included into the bill of material. The ULP script uses a check that I have tried to replicate in my Python script. I tried to perform the following check:
if p is None or p.device is None or p.device.package is None:
continue
This is based on what I found in this example:
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-8E1D5B42-9C0A-4F8E-B3D7-1A2E4F6C8B0D
p.device.package should be 'None' when it doesn't have a footprint. However, it is not 'None'. When for example printing p.device.package.name, it doesn't return 'None', but prints 'SCRIPT ERROR' to the text commands window.
Presumably this is a crash in the underlying API code, which is not passed correctly onto Python?
This can be replicated when in an Electronics schematic, containing parts with and without package with the following script:
import adsk.core, adsk.electron, traceback
def run(context):
app = adsk.core.Application.get()
try:
sch = adsk.electron.Schematic.cast(app.activeProduct)
if sch is None:
app.log("Active product is not a schematic.")
return
parts = sch.parts
if parts is None:
app.log("No parts collection.")
return
part_list = []
for i in range(parts.count):
p = parts.item(i)
if p is None or p.device is None or p.device.package is None:
continue
app.log(str(p.name))
part_list.append(p.device.package.name)
app.log(str(part_list))
except Exception:
app.log(traceback.format_exc() or "Error")