Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
It seems that attributes are duplicated when a component is created from a body. But the parent reference is lost.
Here is a small code:
import adsk.core, adsk.fusion, adsk.cam, traceback # pylint: disable=import-error
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
sketches = rootComp.sketches
sketch1 = sketches.add(rootComp.yZConstructionPlane)
sketchLines = sketch1.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(0, 0, 0)
endPoint = adsk.core.Point3D.create(5.0, 5.0, 0)
sketchLines.addTwoPointRectangle(startPoint, endPoint)
prof = sketch1.profiles.item(0)
extrudes = rootComp.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(5.0)
extInput.setDistanceExtent(False, distance)
extInput.isSolid = True
ext = extrudes.add(extInput)
brepBody = ext.bodies.item(0)
brepBody.attributes.add('BugAttributesComponentFromBody', 'test', 'test')
attributes = design.findAttributes('BugAttributesComponentFromBody', 'test')
msg = 'Before component\n'
for idx, attribute in enumerate(attributes):
if attribute.parent:
msg += '{} - {} - OK\n'.format(idx, attribute.name)
else:
msg += '{} - {} - PB\n'.format(idx, attribute.name)
brepBody.createComponent()
attributes = design.findAttributes('BugAttributesComponentFromBody', 'test')
msg += '\nAfter component\n'
for idx, attribute in enumerate(attributes):
if attribute.parent:
msg += '{} - {} - OK\n'.format(idx, attribute.name)
else:
msg += '{} - {} - PB\n'.format(idx, attribute.name)
ui.messageBox(msg)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Here is the result:
Thank you.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Solved! Go to Solution.