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: 

Can't clear the activeSelections

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
kandennti
951 Views, 10 Replies

Can't clear the activeSelections

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.

10 REPLIES 10
Message 2 of 11
goyals
in reply to: kandennti

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



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 11
kandennti
in reply to: goyals

Thanks @goyals .

 

I expect activeSelections.count after ui.activeSelections.clear() to be "0".

3.png

 

Message 4 of 11
BrianEkins
in reply to: kandennti

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
Message 5 of 11
kandennti
in reply to: BrianEkins

Thanks @BrianEkins.

 

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

 

As described by @Duracellman425 here

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

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.)

Message 6 of 11
thomasa88
in reply to: kandennti

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

Message 7 of 11
kandennti
in reply to: thomasa88

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))
・・・
Message 8 of 11
scottmoyse
in reply to: kandennti

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


Design & Manufacturing Technical Services Manager at Cadpro New Zealand

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

Message 9 of 11
kandennti
in reply to: kandennti

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.

Message 10 of 11
SaeedHamza
in reply to: kandennti

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

is it still not solved?

Message 11 of 11
kandennti
in reply to: SaeedHamza

@SaeedHamza .

 

I still could not deselect when using the selectEntity method.

Therefore, it seems that the only way to do this is to use the above method.

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