Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

selectEntity problem (documentation vs application)

brad.bylls
Collaborator

selectEntity problem (documentation vs application)

brad.bylls
Collaborator
Collaborator

I have script that requires the user to pick a 'PlanarFace'

According to the documentation, this should work.

returnValue = userInterface_var.selectEntity(prompt, filter)

However, when I run the script:

# Create a new sketch.
    sketches = newComp.sketches
    xyPlane = adsk.core.UserInterface.selectEntity('Select Face''PlanarFaces')
    center = adsk.core.Point3D.create(000)
I get this exception error looking for another argument?
 
Error.png

 

Brad Bylls
0 Likes
Reply
Accepted solutions (1)
798 Views
8 Replies
Replies (8)

BrianEkins
Mentor
Mentor

The error is a bit misleading but I think you're getting it because you're attempting to use it like a static function. Instead you need to call it from an existing UserInterface object. Assuming you have a variable named "ui" that references the UserInterface you would call it like this:

xyPlane = ui.selectEntity('Select Face', 'PlanarFaces')
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

kandennti
Mentor
Mentor

Hi @brad.bylls .

 

A follow-up to@BrianEkins' advice.

 

The return value of the selectEntity method will be a Selection object rather than a selected entity.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c05f97b8-9c8f-404b-8b21-f170d194ef8e 

 

You can also press the ESC key during the selection process to abort the process, but this will raise an exception.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-userinterface-selectentity-should-retu... 

 

For this reason, we recommend that you do something like this.

        app = adsk.core.Application.get()
        ui = app.userInterface
        
        try:
            returnValue = ui.selectEntity('Select Face', 'PlanarFaces')
        except:
            return

        xyPlane = returnValue.entity
0 Likes

brad.bylls
Collaborator
Collaborator

I tried that and get the same error.

Brad Bylls
0 Likes

brad.bylls
Collaborator
Collaborator

I tried this.

Did not get an error message, but no UI came on the screen asking to pick a face.

In debugging, I stepped through the code and nothing happened.

Brad Bylls
1 Like

kandennti
Mentor
Mentor

Beyond this, you can't judge without seeing your actual source code.

0 Likes

brad.bylls
Collaborator
Collaborator
 
    ui = adsk.core.UserInterface
    sketches = newComp.sketches
    xyPlane = ui.selectEntity('Select Face''PlanarFaces')
    center = adsk.core.Point3D.create(000)
Brad Bylls
0 Likes

kandennti
Mentor
Mentor
Accepted solution

I've modified this sample here.

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ecd3b76b-19f7-4efa-8a02-087c16da246f 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        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
        try:
            returnValue = ui.selectEntity('Select Face', 'PlanarFaces')
        except:
            return

        xyPlane = returnValue.entity
        
        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)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

I wanted everything to be public, including the declaration part.

0 Likes

brad.bylls
Collaborator
Collaborator

It does not give the user a command prompt to pick a face.

It does work when you do pick a face.

It's just that the user won't know to do that.

Brad Bylls
1 Like