How to combine two bodies in Fusion API?

How to combine two bodies in Fusion API?

Anonymous
Not applicable
2,695 Views
7 Replies
Message 1 of 8

How to combine two bodies in Fusion API?

Anonymous
Not applicable

I need to combine two Brep bodies but each time I try, the CombineFeatures.add Method returns Null.

I get the message: "NoneType object has no attribute 'targetBody'

 


The code is below: 

app = adsk.core.Application.get()

product = app.activeProduct

design = adsk.fusion.Design.cast(product)

model = design.activeComponent

features = model.features

combineFeatures = features.combineFeatures

bodies = model.bRepBodies

body = bodies.item(0)

copyOfBody = body.copyToComponent(model)

bodyCollection = adsk.core.ObjectCollection.create()

bodyCollection.add(copyOfBody)

combineFeatureInput = combineFeatures.createInput(body, bodyCollection)

combineFeatureInput.operation = 0

combineFeatureInput.isKeepToolBodies = False

combineFeatureInput.isNewComponent = False

returnValue = combineFeatures.add(combineFeatureInput)

body = returnValue.targetBody

 

0 Likes
2,696 Views
7 Replies
Replies (7)
Message 2 of 8

kandennti
Mentor
Mentor

Hi.jmperez6

I think that you can process it properly with your code.

(Win7 + Fusion360ver 2.0.4233)

 

10.png

 

 

0 Likes
Message 3 of 8

Anonymous
Not applicable
So there's something wrong with my code?
Also, how did you get that list of object types?
0 Likes
Message 4 of 8

kandennti
Mentor
Mentor

As I indicated in the image, I just executed your code.
I do not think there is any particular problem within this code range.

Message 5 of 8

Anonymous
Not applicable
Ok, well now after running it again, I'm getting this error: "didn't roll edit feature back".
It says it occurs in the returnValue.targetbody line.
What would this mean?
0 Likes
Message 6 of 8

kandennti
Mentor
Mentor
0 Likes
Message 7 of 8

BrianEkins
Mentor
Mentor

The reason for the failure is that the targetBody property returns the original body that was used as input to the feature.  The problem is that after the feature is created that body no longer exists in its original state.  To get it, you need to roll the model back to just before the feature was created.  This is the same thing that happens in the UI when you edit a feature.  You'll see that the timeline rolls back to just before that feature so you see the model in the state it was when the feature was created.  The code below will allow you to do that.

 

returnValue.timelineObject.rollTo(True)       
body = returnValue.targetBody

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 8

martin.j.labrousse
Explorer
Explorer

Hello

 

on my side, it works by changing the lost last lines : 

 

returnValue = combineFeatures.add(combineFeatureInput)

body = returnValue.targetBody

 

and keep only

 

combineFeatures.add(combineFeatureInput)