& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
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.
Solved! Go to Solution.
@kandennti I am not able to reproduce it. Not sure what is going wrong on your side. Thanks.
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.
Thanks @BrianEkins.
I couldn't see any other possibilities for deselecting the selection state other than this.
As described by @Anonymous here
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.)
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))
・・・
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.
RevOps Strategy Manager at Toolpath. New Zealand based.
Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project
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.
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.
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.
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name