Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is this possible ?
Wanting to Cut every body from Component 'B' from every Body in Component 'A'
If I iterate thru the 2 components, and create an ObjectCollection of Bodies, and an ObjectCollection of Tools, can I combine Cut the Tools from the Bodies ( and keep the tools) ?
I have adapted this code to iterate thru the components, but not sure how to add the bodies to the 2 ObjectCollections, or if this will even work at all.
If not, any alternate suggestions ?
This code fails at the 'Combine cut input' line with a long error that I can't understand
import adsk.core, adsk.fusion, traceback
def traverseBODY(occurrences, Ubodies):
# recursive method to get all bodies from components and sub-components
for occ in occurrences:
for bod in occ.bRepBodies:
Ubodies.append(bod)
if occ.childOccurrences:
traverseBODY(occ.childOccurrences, Ubodies)
return Ubodies
def traverseTOOL(occurrences, Utools):
# recursive method to get all bodies from components and sub-components
for occ in occurrences:
for bod in occ.bRepBodies:
Utools.append(bod)
if occ.childOccurrences:
traverseTOOL(occ.childOccurrences, Utools)
return Utools
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
features = rootComp.features
# Get active design
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
return
# History must be captured for this to work
if design.designType == adsk.fusion.DesignTypes.DirectDesignType:
design.designType = adsk.fusion.DesignTypes.ParametricDesignType
# Get root component in this design
rootComp = design.rootComponent
# Get all Components below root
occs = rootComp.occurrences
# add all bodies from all components in the collection
Ubodies = []
Utools = []
# loop thru each root component
for UrootComp in occs:
if UrootComp.name == "ComponentB":
Utools = traverseTOOL(occs, Utools)
else:
Ubodies = traverseBODY(occs, Ubodies)
# Combine Cut
CombineCutInput = rootComp.features.combineFeatures.createInput(Ubodies, Utools)
CombineCutFeats = features.combineFeatures
CombineCutInput = CombineCutFeats.createInput(Ubodies, Utools)
CombineCutInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
CombineCutInput.isKeepToolBodies = True
CombineCutFeats.add(CombineCutInput)
ui.messageBox('Operation Completed')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.