- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Struggling to find why I'm receiving this error ... other than it's a bug-but I will be happily corrected.
Code objective is to extract a bunch of information from sheet metal components so I can create purchase orders in my financial system automatically.
I have chosen to use the material object from component.flatPattern.flatBody to avoid "challenges" where a sheet metal component has become "an assembly" and has downstream components (for example - press fit clinch studs/nuts).
Note -
(1) - I experienced the error on component "No folds" (note the lower case 'f').
(2) - some components use materials from my private material library and I am not sure what happens with them when the f3z archive is created.
Code as follows:
import adsk.core
import adsk.fusion
import traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
allComps: adsk.fusion.Components = design.allComponents
for component in allComps:
processComponent = False
for body in component.bRepBodies:
if body.isSheetMetal:
msg = f'Component \t "{component.name}" has sheet metal body'
app.log(msg)
adsk.doEvents()
if not component.flatPattern:
msg = f'\tNo flat pattern exists'
app.log(msg)
else:
msg = f'\tFlat pattern name = "{component.flatPattern.name}" '
app.log(msg)
flatPatternHealth = component.flatPattern.healthState
# REFER ENUMS to evaluate this.
if flatPatternHealth == adsk.fusion.FeatureHealthStates.HealthyFeatureHealthState:
msg = f'\tComponent will be processed'
app.log(msg)
processComponent = True
"""
bendLinesBody = component.flatPattern.bendLinesBody
for BRepEdge in bendLinesBody.edges:
(retval, isBendUp, bendAngle) = component.flatPattern.getBendInfo(BRepEdge)
msg = f'\tretval:{retval} isBendUp:{isBendUp} bendAngle:{bendAngle}'
app.log(msg)
adsk.doEvents()
"""
if processComponent == True:
if not component.material:
mat = 'No Material'
else:
mat = component.material.name
thickness = component.activeSheetMetalRule.thickness.value
matCode = f'mat_{mat} t={thickness * 10:.1f}'
msg = f'\tMaterial code(1): {matCode}'
app.log(msg)
adsk.doEvents()
matObjType = component.flatPattern.flatBody.material.objectType
msg = f'\tFlat Pattern Material object type: {matObjType}'
app.log(msg)
adsk.doEvents()
mat = component.flatPattern.flatBody.material.name
thickness = component.activeSheetMetalRule.thickness.value
matCode = f'mat_{mat} t={thickness * 10:.1f}'
msg = f'\tMaterial code(2): {matCode}'
app.log(msg)
adsk.doEvents()
except:
if ui:
app.log(f'Failed:\n{ format(traceback.format_exc()) }')
#ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Error
Traceback (most recent call last):
File "D:/Users/Public/G2VDesign_OneDrive/OneDrive - G2V DESIGN PTY LTD/Fusion 360 Tools/Add-ins/$GV Test Bed/$GV Test Bed.py", line 69, in run
mat = component.flatPattern.flatBody.material.name
File "C:\Users/gvisc/AppData/Local/Autodesk/webdeploy/production/414da7cdec4faa7986fe0d205fb521fc68f5d46c/Api/Python/packages\adsk\core.py", line 11404, in _get_name
return _core.Material__get_name(self)
RuntimeError: 2 : InternalValidationError : assetInst
Thanks,
Glenn.
Solved! Go to Solution.