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: 

Creating an inaccessible body inside a base feature

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
nnikbin
444 Views, 5 Replies

Creating an inaccessible body inside a base feature

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

Tags (1)
5 REPLIES 5
Message 2 of 6
nnikbin
in reply to: nnikbin

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

10.png

Message 3 of 6
goyals
in reply to: nnikbin

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
Message 4 of 6
nnikbin
in reply to: goyals

Hi @goyals ,

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

Message 5 of 6
goyals
in reply to: nnikbin

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
Message 6 of 6
nnikbin
in reply to: goyals

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.

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