How can you delete a Component?

How can you delete a Component?

hassan2516
Explorer Explorer
3,377 Views
3 Replies
Message 1 of 4

How can you delete a Component?

hassan2516
Explorer
Explorer

 

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()

0 Likes
Accepted solutions (2)
3,378 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor
Accepted 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. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 4

hassan2516
Explorer
Explorer
Accepted solution

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()

 

0 Likes
Message 4 of 4

hassan2516
Explorer
Explorer

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

 

 

0 Likes