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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Share inputs between event handlers

Message 1 of 6
191 Views, 5 Replies

Share inputs between event handlers

I want to hover over a face and getting the point the the mouse pointer is over at every moment. 
I have been able to do that by using the preselectMouseMove handler. I can print the cursor position to the console. Works perfectly. 
but how can I get that input values into the changed input handler to make a text box update live with the values of the position?

so what I really ask for: how can I access variables/inputs from one event handler in another event handler? Anyone?


@BrianEkins @boopathi.sivakumar @BrianEkinsADSK  

Labels (1)
Message 2 of 6
in reply to: oyvindTMNSU

No one that can point me in the right direction?

Message 3 of 6
in reply to: oyvindTMNSU

You can have global variables in your program. These are defined outside of any functions and that single variable is available within the functions. To set the value of a global variable you need to declare it within the function that will be changing it by using the "global" keyword.

lastPoint: adsk.core.Point3D = None

def getPoint():
    global lastPoint
    lastPoint = adsk.core.Point3D.create(1, 2, 3)

def usePoint():
    app.log(f'The point coords are {lastPoint.x}, {lastPoint.y}, {lastPoint.z}')
Brian Ekins
Inventor and Fusion 360 API Expert
Message 4 of 6
in reply to: BrianEkins

Thank you for answering! I thought I read something that global variables should be avoided. But if that’s the intended way I’ll use that. 

Message 5 of 6
in reply to: oyvindTMNSU

Global variables have their place, and they're often misused, but this is a good case where they make sense. Where you need to share a value between different functions.

Brian Ekins
Inventor and Fusion 360 API Expert
Message 6 of 6
in reply to: BrianEkins

What i want to do is to get the coordinates on a face when hoovering over with the mouse. I get that by doing this and it prints out the position perfectly in the debug console. 


# Event handler for the preSelectMouseMove event
def command_preSelectMouseMove(args: adsk.core.SelectionEventArgs):
    # Code to react to the event
    inputs = args.selection
    hoover_test: adsk.core.SelectionCommandInput = args.selection
    hoover_point = inputs.point
    # print(f'{inputs.entity}')

Now I want to display the hoover_point readings (live as the mouse moves) in a dialog box as a text. Meaning I need to transfer the hoover_point variable over to def command_inputChanged


# This function will be called when the user changes anything in the command dialog.
def command_inputChanged(args: adsk.core.InputChangedEventArgs):
    changed_input = args.input
    inputs = args.inputs
    futil.log(f'{CMD_NAME} Input Changed Event fired from a change to {}')

    start_point_selection_input: adsk.core.SelectionCommandInput = inputs.itemById('spline_start')
    position_box: adsk.core.TextBoxCommandInput = inputs.itemById('position_box')
    type_box: adsk.core.TextBoxCommandInput = inputs.itemById('type_box')

But I don’t get it to work, even if I make the hoover_point variable global. Maybe I do something wrong when I set up the global variable?🤷 would really appreciate an answer on this. Feels like this is a part of the add writing I just don’t get 100%. 

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