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: 

Text Commands

3 REPLIES 3
Reply
Message 1 of 4
carloquinonez
2434 Views, 3 Replies

Text Commands

Is there a way to add new commands to the "Text Commands" window? Or to log output from scripts to the "Text Commands" window?

 

 


-CQ
3 REPLIES 3
Message 2 of 4
liujac
in reply to: carloquinonez

Hi,

 

Fusion 360 currently does not support to add external text commands. It is able to run python script in Text Commands window. So one workaround, you may write your text commands in python script and run python script in Text Commands window. For example:

1. Create a python script named "MyTextCommands" with the following content.

import adsk.core, traceback

def showMessageBox(msg):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        ui.messageBox(msg)
        print('Message: ' + msg)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

2.Show text commands window, choose radio "py".

3.Add the folder path of "MyTextCommands.py" to sys.path:

   Enter "import sys" in text commands window.

   Enter "sys.path.insert(0, "C:/Users/liujac/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/MyTextCommands")" in in text commands window.

4.Enter "import MyTextCommands" in text commands window.

5.Enter "MyTextCommands.showMessageBox("Hello World")" in text commands window. The message box is displayed and the message is print in text commands window.

Capture.PNG

 

I'm not sure if this is exactly what you expected. It would be great if you can share more detailed info about your workflow, that would be helpful for us to understand the requirements.

 

Regards,

Jack

 

Message 3 of 4
carloquinonez
in reply to: liujac

That's cool, but not exactly what I was looking for. What I'm trying to figure out is how to provide a text-based UI for custom commands. I want to be able to pass in parameters/args into fusion commands and display console output. GUIs are nice - but sometimes console interfaces make more sense, especially in the early stages when I'm just prototyping or trying to build a proof-of-concept.

 

In the long term, I'm working towards a "make" or "grunt"-style workflow for compiling/building CAD designs, but in the short-term, having API access to the Text Commands window would make development a little easier since debugging doesn't work on my work Mac and I end up having to pepper my code with console.log (er... ui.MessageBox) commands to debug anything.


-CQ
Message 4 of 4

It's probably better these days using the inbuilt script IDE - choose the "Tools" menu, then "Add-ins"

"Scripts and Add-ins" then click "create" for a script or addin, then you get a new window where you can run and debug your scripts.  This lets you log to the IDE console message log area:

 

def eprint(*args, **kwargs):  # Print debug stuff to STDERR
    global userdata
    if userdata['debug']:
        print(*args, file=sys.stderr, **kwargs)

 

the few extra minutes to get that worked out will save you hours and hours of pain and head-scratching - it's way better than ui.messageBox plus it also traps other errors with explanations too, and in the IDE is exactly what you asked for as well - a full command line where you can run stuff and inspect things etc.

 

And, since you did ask, here's how to write into the Text Commands output window:

 

ui.palettes.itemById('TextCommands').writeText("Hello")

 

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