<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding attributes to the Design empties SelectionCommandInput.selection in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642956#M19142</link>
    <description>&lt;P&gt;Adding attributes to the Design causes the SelectionCommandInput.selectionCount to return 0 and so SelectionCommandInput.selection(index) will fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the following code block the following&amp;nbsp;line (line 57) causes the&amp;nbsp;s&lt;SPAN&gt;electionCommandInput.selectionCount to return 0:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;design.attributes.add('TestGroup', 'TestName', 'TestValue')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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()))&lt;/PRE&gt;&lt;P&gt;As a workaround I add the attributes to the Design after getting the selection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it a bug or this behavior is 'By Design'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Oct 2016 02:11:23 GMT</pubDate>
    <dc:creator>nnikbin</dc:creator>
    <dc:date>2016-10-25T02:11:23Z</dc:date>
    <item>
      <title>Adding attributes to the Design empties SelectionCommandInput.selection</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642956#M19142</link>
      <description>&lt;P&gt;Adding attributes to the Design causes the SelectionCommandInput.selectionCount to return 0 and so SelectionCommandInput.selection(index) will fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the following code block the following&amp;nbsp;line (line 57) causes the&amp;nbsp;s&lt;SPAN&gt;electionCommandInput.selectionCount to return 0:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;design.attributes.add('TestGroup', 'TestName', 'TestValue')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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()))&lt;/PRE&gt;&lt;P&gt;As a workaround I add the attributes to the Design after getting the selection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it a bug or this behavior is 'By Design'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 02:11:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642956#M19142</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2016-10-25T02:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding attributes to the Design empties SelectionCommandInput.selection</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642960#M19143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's as designed. Any edit to document will clear all the selections first. So you need to get the entities from the selections before doing any edit operations to the document if you want to use the selected entities later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 02:06:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642960#M19143</guid>
      <dc:creator>liujac</dc:creator>
      <dc:date>2016-10-25T02:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding attributes to the Design empties SelectionCommandInput.selection</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642967#M19144</link>
      <description>&lt;P&gt;Hi Jack,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your prompt reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Navid&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 02:14:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/6642967#M19144</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2016-10-25T02:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding attributes to the Design empties SelectionCommandInput.selection</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/7956431#M19145</link>
      <description>&lt;P&gt;I'm so happy to have found this post. It just cost me a few days to track down this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I can tell this is not documented in the API User's Manual or the API Reference Manual. If that is indeed so, maybe it would be worth adding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:15:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/adding-attributes-to-the-design-empties-selectioncommandinput/m-p/7956431#M19145</guid>
      <dc:creator>martinhansdk</dc:creator>
      <dc:date>2018-04-24T18:15:43Z</dc:date>
    </item>
  </channel>
</rss>

