Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Text Commands

carloquinonez
Advocate

Text Commands

carloquinonez
Advocate
Advocate

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
1 Like
Reply
2,906 Views
5 Replies
Replies (5)

liujac
Alumni
Alumni

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

 

0 Likes

carloquinonez
Advocate
Advocate

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
0 Likes

OceanHydroAU
Collaborator
Collaborator

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")

 

2 Likes

dvorksign
Community Visitor
Community Visitor

I dont know if I am too late but this doesnt work for me. It does write the exact line but the actual function is not performed.

This is my line: 

ui.palettes.itemById('TextCommands').writeText("Sketch.ShowUnderconstrained")

 

 

Do I need some sort of execute command after this line?

0 Likes

kandennti
Mentor
Mentor

Hi @dvorksign -San.

 

I think it would work this way.

adsk.core.Application.get().executeTextCommand(“Sketch.ShowUnderconstrained”)

 

If it is too much trouble to type it every time, the “Sketch Analysis” command in the add-in published here would work similarly.
https://github.com/kantoku-code/Fusion360_SketchToolPlus 

0 Likes