BaseFeature.updateBody causes downstream failures
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on an add-in which creates a body and can later be used to replace that same body with a modified version, based on external conditions. This code was working fine until a few months ago, perhaps with the February release. Something changed with Fusion so that every time my add-in replaced an existing body, the body name would increment and any features that depended on that body would lose track of it. This hits me right in the use-case, and I've not been able to find a workaround.
I've isolated the behavior in a simple script (below) in hopes of finding a workaround or fix. The first time this script is run it creates a sphere, a cylinder, each in their own BaseFeature, and cuts one from the other. On subsequent runs it replaces the sphere within its BaseFeature. After the second run, note three things:
- The sphere is now named "Body3", not "Body1" as expected.
- The cylinder is no longer translucent.
- The Combine feature fails because it no longer knows its target body, which used to be the sphere.
The first two problems are weird but tolerable. The third is what's causing me grief. Can anyone shed any light on this?
Thanks,
-Gina
app = adsk.core.Application.get()
design = adsk.fusion.Design.cast(app.activeProduct)
component: adsk.fusion.Component = design.rootComponent
tbrm = adsk.fusion.TemporaryBRepManager.get()
if component.features.baseFeatures.count == 0:
sphereFeature = component.features.baseFeatures.add()
sphereFeature.startEdit()
sphere = tbrm.createSphere(adsk.core.Point3D.create(0, 0, 1), 1)
component.bRepBodies.add(sphere, sphereFeature)
sphereFeature.finishEdit()
cylinderFeature = component.features.baseFeatures.add()
cylinderFeature.startEdit()
cylinder = tbrm.createCylinderOrCone(adsk.core.Point3D.create(1, 1, 0), 1, adsk.core.Point3D.create(1, 1, 2), 1)
component.bRepBodies.add(cylinder, cylinderFeature)
cylinderFeature.finishEdit()
cylinderFeature.bodies.item(0).opacity = 0.5
tools = adsk.core.ObjectCollection.create()
tools.add(cylinderFeature.bodies.item(0))
input = component.features.combineFeatures.createInput(sphereFeature.bodies.item(0), tools)
input.isKeepToolBodies = True
input.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
combineFeature = component.features.combineFeatures.add(input)
else:
sphereFeature = component.features.baseFeatures.item(0)
rolledTimelineObject = design.timeline.item(design.timeline.markerPosition - 1)
sphereFeature.timelineObject.rollTo(rollBefore = True)
sphereFeature.startEdit()
sphere = tbrm.createSphere(adsk.core.Point3D.create(0, 0, random.uniform(0.5, 1.5)), 1)
sphereFeature.updateBody(sphereFeature.bodies.item(0), sphere)
sphereFeature.finishEdit()
rolledTimelineObject.rollTo(rollBefore=False)