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: 

Update User defined Inputs

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
changedsoul
1201 Views, 7 Replies

Update User defined Inputs

I am trying my hand at creating a custom script. I am using the Spurgear as my base because all I want to do is add some functionality to it, and also get it working with inches and not cm.

 

I added a few more user inputs, for more control on the gear generation. What I wanted to do was have some of the inputs udate based on other inputs changing.

For example, I added an input for the Outside diam, which changes based on number of teeth and or Diametral Pitch. This value is auto calulated and filled in at first start from the default values, but then can be modified if what is wanted is something other than a standard gear.

 

If the user changes the Number Of Teeth, I would like the Outside Diam to get re calculated and updated.

I belive this would be implimented in the Validator section of code, but I cant seem to find info on updating the user interface other than when it is initially created.

 

My hopes is, when I get this working, is to add many options for creating custom gears, with the users input of any number of things like backlash, modified tooth thickness, non standard pitch diam, etc.

 

Any ideas on how to have the dialog update based on changes, before the user clicks "ok".

And for a bonus, but this will be later after its working, is to have ot preview the gear before ok is presses....or at least preview a sketch.

 

Anyways, my main issue is trying to get the UI to update before ok is pressed.

 

Any ideas?

7 REPLIES 7
Message 2 of 8
zhijie.li
in reply to: changedsoul

You can use inputChanged event in Command to update the command inputs by setting the value. There is some code in sample ApplyAppearanceToSelection you can refer to:

 

# ApplyAppearanceInputChangedHandler will be called if the value of any input is changed
class ApplyAppearanceInputChangedHandler(adsk.core.InputChangedEventHandler): def __init__(self): super().__init__() def notify(self, args): try: cmd = args.firingEvent.sender inputs = cmd.commandInputs appearanceListInput = None materialLibInput = None filterInput = None global commandId for inputI in inputs: if inputI.id == commandId + '_appearanceList': appearanceListInput = inputI elif inputI.id == commandId + '_materialLib': materialLibInput = inputI elif inputI.id == commandId + '_filter': filterInput = inputI
# change the input value here to upate the inputs cmdInput = args.input if cmdInput.id == commandId + '_materialLib' or cmdInput.id == commandId + '_filter': appearances = getAppearancesFromLib(materialLibInput.selectedItem.name, filterInput.value) replaceItems(appearanceListInput, appearances) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

class ApplyAppearanceCreatedHandler(adsk.core.CommandCreatedEventHandler):    
    def __init__(self):
        super().__init__()        
    def notify(self, args):
        try:
            cmd = args.command
            onExecute = ApplyAppearanceExecuteHandler()
            cmd.execute.add(onExecute)
            
            onDestroy = ApplyAppearanceDestroyHandler()
            cmd.destroy.add(onDestroy)
            onInputChanged = ApplyAppearanceInputChangedHandler()
            cmd.inputChanged.add(onInputChanged) # add inputChanged handler
            # keep the handler referenced beyond this function
            handlers.append(onExecute)
            handlers.append(onDestroy)
            handlers.append(onInputChanged)

 

Message 3 of 8
changedsoul
in reply to: zhijie.li

Thanks for the responce. I will give it a shot soon and see if I am able to easily impliment it. I am just starting out so it might be a few days before I understand things.

By the way, how were you able to locate this information? I tried the API documentation, but this is very confusion how it is laid out.

Message 4 of 8
zhijie.li
in reply to: changedsoul

First, it is suggested to look into page Welcome to Fusion's Programming Interface to see how to use the help document.

Second, it is better to go through the items in Fusion 360 API User's Manual for basic use and general ideas about API.

And then, the best way to learn is looking into the code and practise. For how to use specific object or method, you can search it in the help document or find it in Fusion 360 API Reference Manual. There are some code samples in "Scripts and Add-Ins" dialog. You can click edit to see the code.

At last, if there is any question, welcome to post it here. We will do our best to reply it in time and help you to solve problem.

 

QQ图片20160223094112.jpg

Message 5 of 8
changedsoul
in reply to: changedsoul

Thanks for the post, I didnt see the sample scripts....I should have looked :(.

Message 6 of 8
changedsoul
in reply to: changedsoul

Ok, I am royaly confused!

I am sorry, I know a lot of time probably went into this API documentation, but the format sux.

Can someone help me figure this out? This is what I am having trouble trying to figure out, and I will use the "ApplyAppearance..." script for my basis.

 

 

   ........
            cmd = args.firingEvent.sender
            
            inputs = cmd.commandInputs
            appearanceListInput = None
            materialLibInput = None
            filterInput = None
            global commandId
            for inputI in inputs:
                if inputI.id == commandId + '_appearanceList':
1:.................appearanceListInput = inputI
                elif inputI.id == commandId + '_materialLib':
                    materialLibInput = inputI
                elif inputI.id == commandId + '_filter':
                    filterInput = inputI
2:............cmdInput = args.input
3:............if cmdInput.id == commandId + '_materialLib' or cmdInput.id == commandId + '_filter':
                appearances = getAppearancesFromLib(materialLibInput.selectedItem.name, filterInput.value)
4:.............replaceItems(appearanceListInput, appearances)
 .....

 

I am trying to follow along, trying to understand so i can apply it to another script.

To start off, I see when the input changes, it fires off "ApplyAppearanceInputChangedHandler"

Good...so far so good, yay for me!

1: Next it finds what ever "commandInput" is in "commandInputs" that "_appearanceList" belongs to, and assigns it to "appearanceListInput", so "appearanceListInput" is of type "commandInput" (no "s" on end, so its not "commandInputs"(?) )

 

2: "cmdInput" then gets assigned what ever "input" called the change function, and

3: this then checks if its a filter or a material library.

4: This then passes the "appearanceListInput" and filter onto the "replaceItems" function.

 

here is where I am confused, and the documentation seems very unclear.

def replaceItems(cmdInput, newItems):
    clearAllItems(cmdInput)
    if len(newItems) > 0:
        for item in newItems:
            cmdInput.listItems.add(item, False, '')
        cmdInput.listItems[1].isSelected = True   
        cmdInput.listItems[0].deleteMe()

cmdInput is of type commandInput(?) i think.....and so with me thinking this, I search the API documentation for "commandInput" and find this page:

http://fusion360.autodesk.com/learning/learning.html?guid=GUID-3949772f-20de-4ad3-a1a9-2c6be429ad13

But this doesnt list a member "listItems" of commandInput(aka cmdInput).

 

So this is where I am getting very frustrated and confused. """IF""" cmdInput is of type commandInput, why is there not listed the member "listItems" on the documentation, and also using intelisense there doesnt seem to show anything other than "id".

 

Can someone please help clearify this a bit for me? I do have some background in c++ programming, I am by far no expert though.

 

 

 

Message 7 of 8
zhijie.li
in reply to: changedsoul

For python script, the parameter of function can be any type of object. In this script, the parameter cmdInput will always passed in as DropDownCommandInput(CommandInput is its base class). To know the type of the command input in Python, you can check it during debuging or check the code where it is created.

For code where it is created:

            appearanceListInput = inputs.addDropDownCommandInput(commandId + '_appearanceList', 'Appearance', adsk.core.DropDownStyles.TextListDropDownStyle)

appearanceListInput is created by addDropDownCommandInput method of CommandInputs. You can search the method and will find the returned object type.

 

By debugging, you can find the object type in "Variable inspector" as following image:

QQ图片20160225131249.jpg

Message 8 of 8
changedsoul
in reply to: zhijie.li

Ahhhh, thank you for pointing that out. I am starting to see things better now. I didnt go back far enough and see when the dialog was created and where to see just what type it was. Another problem I was having was how to find out what methods were available to these objects, but I guess I was finding the wrong results in the search. What ever it was, something clicked in my head after seeing your post....I searched for "CommandInputs", which returned the results and "addDropDownCommandInput" method was amung them. I think this is what was confsing me. I cant really explain it, but then after digging into "addDropDownCommandInput" I noticed it had Return Type of "DropDownCommandInput" which is what I was missing all this time, and this had the methods I was looking for and could not ever seem to find.

 

Now I am starting to get the hang of this a bit more, thanks for the help, I am sure I will be back. I take back my comment about th API documentation sucking....I was really frustrated, I apoligize.

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