Sample addin to create button to set active units?

Sample addin to create button to set active units?

graham.wideman
Advocate Advocate
412 Views
2 Replies
Message 1 of 3

Sample addin to create button to set active units?

graham.wideman
Advocate
Advocate

Hi all. I need the same functionality as described in this post:

 

... in which we would ultimately like to have single shortcut keys to quickly switch between, say, mm and inches as the active units.  To get there apparently we first have to have buttons on a toolbar somewhere, and to make that happen we need to write an addin with a couple of commands. 

In the post referenced above, that task was beyond the knowledge of the Autodesk Principal Engineer who responded... so to speed things up, I would greatly appreciate it if someone would share such an addin that they had already done, or indeed any addin that does something similar.  (I do know my way around Python, it's just that the F360 addin API involves a lot of apparatus just to achieve this simple task that I'd rather not flounder my way to enlightenment about.)

 

Not the least missing knowledge is the objects and methods involved in setting active units to some desired setting.

 

Thanks all!

 

 

0 Likes
Accepted solutions (1)
413 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @graham.wideman -San.

 

I made an add-in.
Please register and run the add-in in the attached file.
The command “Length Units Changer” will be added to the red marked area below.

1.png

 

Each time the command is executed, the green mark changes the units by “Millimeter <-> Inch”.
It does not change when other units are used.

If this is the case, “Length Units Changer” can be registered as a shortcut key.

Message 3 of 3

graham.wideman
Advocate
Advocate

Wow! This is fantastic! Thank you very much for going to the effort of writing this add-in, and also providing the screenshot to show how to set the keyboard shortcut, that was very helpful.

 

I see that you have implemented this add-in within just one python file, plus the manifest file. As an example of how to create such an add-in, this is a whole lot clearer than the sample add-in provided by Fusion 360. That example has a lot of distracting features and multiple files which might be useful for a complex add-in, but don't help in understanding the bare bones requirements.

 

One point I will make for others who might want to use this add-in:

 

> Please register and run the add-in in the attached file.

This sort of corresponds to instructions here:

How to install an add-in or script in Fusion 

 

To be clear,

  • this add-in is packaged inside a folder LengthUnitsChanger.
  • Drag or copy that folder to:
    • C:\Users\[user]\AppData\Roaming\Autodesk\Autodesk Fusion 360\API\AddIns
    • ... or similar for your OS
  • NOTE: When you unzip, you might end up with folder ...\LengthUnitsChanger\LengthUnitsChanger\...contents.   Only the innermost LengthUnitsChanger folder should be copied to the Fusion AddIns folder.
  • There is no specific "register" step so far as I can tell. Just copying the provided LengthUnitsChanger folder to the right location is enough for F360 to recognize it...
  • Next time you use Fusion's UTILITIES > UTILITY > ADD-INS > Scripts and Add-Ins dialog > Add-Ins tab, you should see LengthUnitsChanger listed.  You can then run it.
    • You might also check the "Run on startup"checkbox so that the add-in is active for subsequent F360 sessions.
  • After running it, an item "Change Keyboard Shortcut" should appear at UTILITIES > UTILITY as shown in kandennti's screenshot, and then you can assign a hotkey.

Once again, thanks so much for creating this add-in!