Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can you delete a Component?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
hassan2516
2822 Views, 3 Replies

How can you delete a Component?

 

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

3 REPLIES 3
Message 2 of 4
BrianEkins
in reply to: hassan2516

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
Message 3 of 4
hassan2516
in reply to: BrianEkins

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

 

Message 4 of 4
hassan2516
in reply to: hassan2516

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report