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: 

selectEntity problem (documentation vs application)

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
brad.bylls
499 Views, 8 Replies

selectEntity problem (documentation vs application)

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
8 REPLIES 8
Message 2 of 9
BrianEkins
in reply to: brad.bylls

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
Message 3 of 9
kandennti
in reply to: brad.bylls

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
Message 4 of 9
brad.bylls
in reply to: BrianEkins

I tried that and get the same error.

Brad Bylls
Message 5 of 9
brad.bylls
in reply to: kandennti

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
Message 6 of 9
kandennti
in reply to: brad.bylls

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

Message 7 of 9
brad.bylls
in reply to: kandennti

 
    ui = adsk.core.UserInterface
    sketches = newComp.sketches
    xyPlane = ui.selectEntity('Select Face''PlanarFaces')
    center = adsk.core.Point3D.create(000)
Brad Bylls
Message 8 of 9
kandennti
in reply to: brad.bylls

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.

Message 9 of 9
brad.bylls
in reply to: kandennti

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

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