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: 

Bug? UserInterface.selectEntity should return None but fails

4 REPLIES 4
Reply
Message 1 of 5
JeromeBriot
263 Views, 4 Replies

Bug? UserInterface.selectEntity should return None but fails

Hello,

 

According to the documentation, the UserInterface.selectEntity method returns None if the selection is aborted.

 

I guess that the selection is aborted by pressing the Esc key. But in that case, the method returns an error message:

fusion-360-api-selectEntity-failed.png

Here is a code to reproduce the issue:

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        # Draw some circles.
        circles = sketch.sketchCurves.sketchCircles
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
        circle2 = circles.addByCenterRadius(adsk.core.Point3D.create(8, 3, 0), 3)

        # Add a circle at the center of one of the existing circles.
        circle3 = circles.addByCenterRadius(circle2.centerSketchPoint, 4)

        selection = ui.selectEntity('Select a profile', 'Profiles')

        if not selection:
            ui.messageBox('No profile selected')
        else:
            ui.messageBox('One profile selected')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thanks.

4 REPLIES 4
Message 2 of 5
dinocoglitore
in reply to: JeromeBriot

I found the same problem with the selection of a Body. 

bodySel = ui.selectEntity('Select a body''Bodies')
        if bodySel:
            body = adsk.fusion.BRepBody.cast(bodySel.entity)
        elif bodySel == None:
            ui.messageBox("Selection not correct")
            exit
 
If I look at the bodySel variable inside Debug Console this is the answer:
variable.JPG
Thanks
Dino
Message 3 of 5
kandennti
in reply to: JeromeBriot

Hi .

 

This has been happening for a long time.
I always respond using try-except.

 

・・・
        # Add a circle at the center of one of the existing circles.
        circle3 = circles.addByCenterRadius(circle2.centerSketchPoint, 4)

        selection = selectEnt(ui, 'Select a profile', 'Profiles')

        if selection is None:
            ui.messageBox('No profile selected')
        else:
            ui.messageBox('One profile selected')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def selectEnt(ui, msg, filtter_str):
    try:
        selection = ui.selectEntity(msg, filtter_str)

        return selection
    except:
        return None
Message 4 of 5
JeromeBriot
in reply to: kandennti

Thank you@kandennti 

This workaround works perfectly!

Message 5 of 5
dinocoglitore
in reply to: kandennti

Thanks a lot.

Dino

 

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