I am using the CombineCut tool to create a new component by setting the isNewComponent to True. I cannot figure out how to delete the new component from the browser at the end of the script. I can delete the new Body by using newBody.deleteMe() but there is no deleteMe method on Components. How can you delete a Component?
Thanks,
Scott
Here is a snippet of my code:
CombineCutInput = rootComp.features.combineFeatures.createInput(targetBody, toolBodies)
CombineCutInput.operation = adsk.fusion.FeatureOperations.IntersectFeatureOperation
CombineCutInput.isKeepToolBodies = True
CombineCutInput.isNewComponent = True
ret = rootComp.features.combineFeatures.add(CombineCutInput)
newBody = ret.bodies.item(0)
newComponent = newBody.parentComponent
newBody.deleteMe()
Solved! Go to Solution.
Solved by hassan2516. Go to Solution.
Solved by BrianEkins. Go to Solution.
It's not a component that you see in the browser but is an occurrence that references a component. Components can't be directly deleted but the Occurence object supports the deleteMe method and if all the occurrences that reference a particular component are deleted, Fusion will automatically delete the component.
Ahhh... that did the trick. Here is the code to remove the component by using the rootComp and searching for the newly created component.
Thanks,
Scott
ret = rootComp.features.combineFeatures.add(CombineCutInput)
newBody = ret.bodies.item(0)
## delete the newly created component from the intersection
newComponent = newBody.parentComponent
for occurrence in rootComp.occurrencesByComponent(newComponent):
occurrence.deleteMe()
I went one step further by making a class method on Component called deleteMe so that you can just call deleteMe on a component to delete it.
Scott
def component_deleteMe(self):
app = adsk.core.Application.get()
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
for occurrence in rootComp.occurrencesByComponent(self):
occurrence.deleteMe()
adsk.fusion.Component.deleteMe = component_deleteMe
Can't find what you're looking for? Ask the community or share your knowledge.