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

Can't clear the activeSelections

kandennti
Mentor

Can't clear the activeSelections

kandennti
Mentor
Mentor

I want to clear the activeSelections, but if they are selected using userInterface.selectEntity, they will not be cleared.

import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        msg :str = 'select SolidBody'
        selFiltter :str = 'SolidBodies'
        _ui.selectEntity(msg, selFiltter)

        actSels = _ui.activeSelections
        _ui.messageBox('Before clearing count : {}'.format(actSels.count))

        actSels.clear()
        _ui.messageBox('After clearing count : {}'.format(actSels.count))

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

As far as I remember, I was able to clear it.
I'm using Fusion360 Ver 2.0.8749.

0 Likes
Reply
Accepted solutions (1)
1,422 Views
10 Replies
Replies (10)

goyals
Autodesk
Autodesk

@kandennti  I am not able to reproduce it. Not sure what is going wrong on your side. Thanks.



Shyam Goyal
Sr. Software Dev. Manager
1 Like

BrianEkins
Mentor
Mentor

I can reproduce it.  I'm a bit surprised that the selectEntity method is adding the entity to the active selection.  But since it appears that's what is happening you would expect the clear to remove it.  I'll work with Shyam to log this.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

kandennti
Mentor
Mentor

Thanks @BrianEkins.

 

I couldn't see any other possibilities for deselecting the selection state other than this.

 

As described by @Anonymous here

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/selectentity-causes-fusion-to-crash/m-p/9674994#M10903 

I'm wondering if this is due to the addition of "activeSelectionEvent".

 

I've confirmed that the event is fired when selecting with selectEntity and not when using the clear method.
(Since it is not cleared, I think you are correct that the event is not fired.)

0 Likes

thomasa88
Advocate
Advocate

Does it work if you use e. g. removeByIndex ()?

0 Likes

kandennti
Mentor
Mentor

Thanks @thomasa88 .

 

I tried "removeByIndex", "removeByEntity" and "removeBySelection" with the same result.

I can clear the selections.add.

ใƒปใƒปใƒป
        _ui.messageBox('Before clearing count : {}'.format(actSels.count))

        # actSels.clear()
        # actSels.removeByIndex(0)
        # actSels.removeByEntity(actSels.item(0).entity)
        actSels.removeBySelection(actSels.item(0))
        _ui.messageBox('After clearing count : {}'.format(actSels.count))

        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent
        _ui.activeSelections.add(root.xYConstructionPlane)
        _ui.messageBox('add xyPlane count : {}'.format(actSels.count))

        actSels.clear()
        _ui.messageBox('clearing again count : {}'.format(actSels.count))
ใƒปใƒปใƒป
1 Like

scottmoyse
Mentor
Mentor

I'm pretty sure this change is now crashing my add-in. Any command that uses selectEntity, then passes that entity to a native Fusion command crashes to CER.


Scott Moyse
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature


RevOps Strategy Manager at Toolpath. New Zealand based.

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

0 Likes

kandennti
Mentor
Mentor
Accepted solution

I tried various things I could think of.

# Fusion360 ver2.0.9313
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        msg :str = 'select SolidBody'
        selFiltter :str = 'SolidBodies'
        sel = _ui.selectEntity(msg, selFiltter)

        actSels = _ui.activeSelections
        dumpMsg('Before clearing count : {}'.format(actSels.count))

        # NG
        actSels.clear()
        dumpMsg('After clearing count(Selections.clear Method) : {}'.format(actSels.count))

        # NG
        _app.executeTextCommand(u'Selections.Clear')
        dumpMsg('After clearing count(TextCommands-Selections.Clear) : {}'.format(actSels.count))

        # NG
        _app.executeTextCommand(u'PSelections.Clear')
        dumpMsg('After clearing count(TextCommands-PSelections.Clear) : {}'.format(actSels.count))

        # NG
        _app.executeTextCommand(u'Selector.Clear')
        dumpMsg('After clearing count(TextCommands-Selector.Clear) : {}'.format(actSels.count))

        # NG
        id = _app.executeTextCommand(u'Selections.List').rstrip('\n\r')
        _app.executeTextCommand(u'Selections.Add {}'.format(id))
        _app.executeTextCommand(u'Selections.Clear')
        dumpMsg('After clearing count(TextCommands-Reselect by entityID and Clear) : {}'.format(actSels.count))

        # OK
        ent = sel.entity
        _app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd')
        actSels.add(ent)
        _app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd')
        actSels.clear()
        dumpMsg('After clearing count(SelectabilityToggle) : {}'.format(actSels.count))

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

def dumpMsg(msg :str):
    _ui.palettes.itemById('TextCommands').writeText(str(msg))

 

By switching the Selectability, I was able to force the selection to be cleared, but it is cumbersome.

0 Likes

SaeedHamza
Advisor
Advisor

I've been having a hard time with this too ...

is it still not solved?

Saeed Hamza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes

kandennti
Mentor
Mentor
0 Likes