Creating an inaccessible body inside a base feature

Creating an inaccessible body inside a base feature

nnikbin
Collaborator Collaborator
1,103 Views
5 Replies
Message 1 of 6

Creating an inaccessible body inside a base feature

nnikbin
Collaborator
Collaborator

Please follow the following steps:

  1. Create a sphere
  2. Run the following code
  3. Select the Sphere created in step 1
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None 
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        
        bodySelect = ui.selectEntity('Select the body.', 'Bodies')
        body = adsk.fusion.BRepBody.cast(bodySelect.entity)
        
        component = body.parentComponent
        occurrences = component.occurrences
        occurrence = occurrences.addNewComponent(adsk.core.Matrix3D.create())
        
        #baseFeatures = occurrence.component.features.baseFeatures
        baseFeatures = component.features.baseFeatures
        baseFeature = baseFeatures.add()
        
        baseFeature.startEdit()
        body.copyToComponent(occurrence)
        baseFeature.finishEdit()
        
        body.deleteMe()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The result which is shown in the attached picture will be a sphere residing inside a component, but actually the sphere will be inside a base feature of the parent of the component. So the sphere will not be shown in the browser and it will not be selectable as a BRepBody for commands that need a BRepBody (like Split Body command).

 

My question is: Is it by design or Fusion 360 API should not allow such a situation to occur?

 

It is obvious that uncommenting line 18 and deleting line 19 will solve the problem.

 

9.png

0 Likes
Accepted solutions (1)
1,104 Views
5 Replies
Replies (5)
Message 2 of 6

nnikbin
Collaborator
Collaborator

Uncommenting line 18 and deleting line 19 will produce the following result:

10.png

0 Likes
Message 3 of 6

goyals
Autodesk
Autodesk

This is by design. While editing the base feature in a component, existing bodies present in that component are in read only mode and it is not allowed to paste them in other component. You can check the behaviour through UI. Thanks



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 4 of 6

nnikbin
Collaborator
Collaborator

Hi @goyals ,

Thanks for your response. So I think the API should prevent it. Is it correct?

0 Likes
Message 5 of 6

goyals
Autodesk
Autodesk
Accepted solution

Ideally Yes but I hope you understand it is not always possible always to replicate in API what is happening through UI.  For example in this case you got the body reference before you start editing the base feature which is not possible through UI. Only possible fix I see is to return error status after the copyToComponent API failed. Any opinion?



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 6 of 6

nnikbin
Collaborator
Collaborator

Thank you @goyals  for your reply. I understand. I totally agree with you that returning error status is better than doing the job with an undesirable outcome.

0 Likes