Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Adding attributes to the Design causes the SelectionCommandInput.selectionCount to return 0 and so SelectionCommandInput.selection(index) will fail.
In the following code block the following line (line 57) causes the selectionCommandInput.selectionCount to return 0:
design.attributes.add('TestGroup', 'TestName', 'TestValue')
import adsk.core, adsk.fusion, traceback
app = None
ui = None
selectionCommandInput = None
commandId = 'AttributesAndSelectionCommandInput'
commandName = 'Attributes and Selection Command Input'
commandDescription = 'Attributes and Selection Command Input Test'
handlers = []
class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
adsk.terminate()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global selectionCommandInput
try:
cmd = args.command
inputs = cmd.commandInputs
global commandId
selectionCommandInput = inputs.addSelectionInput(commandId + '_selection', 'Selection', '')
onExecute = MyCommandExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
onDestroy = MyCommandDestroyHandler()
cmd.destroy.add(onDestroy)
handlers.append(onDestroy)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class MyCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
global ui
global selectionCommandInput
design = adsk.fusion.Design.cast(app.activeProduct)
#Removing the following line solves the problem
design.attributes.add('TestGroup', 'TestName', 'TestValue')
ui.messageBox(str(selectionCommandInput.selectionCount))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
ui = None
try:
global app
app = adsk.core.Application.get()
global ui
ui = app.userInterface
global commandId
global commandName
global commandDescription
cmdDef = ui.commandDefinitions.itemById(commandId)
if not cmdDef:
cmdDef = ui.commandDefinitions.addButtonDefinition(commandId, commandName, commandDescription)
onCommandCreated = MyCommandCreatedHandler()
cmdDef.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
cmdDef.execute()
adsk.autoTerminate(False)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))As a workaround I add the attributes to the Design after getting the selection.
Is it a bug or this behavior is 'By Design'?
Website: https://perceptino.com
Solved! Go to Solution.