Skip to content

Commit b655fc2

Browse files
committed
Find options file on Macs (untested)
1 parent dcdaf67 commit b655fc2

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

KeyboardShortcutsSimple.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import adsk.core, adsk.fusion, adsk.cam, traceback
2323

2424
from collections import defaultdict
25-
import ctypes
2625
import json
2726
import operator
2827
import os
29-
import pathlib
3028
import sys
3129
from tkinter import Tk
3230
import xml.etree.ElementTree as ET
@@ -132,7 +130,7 @@ def get_data():
132130
key=lambda w: w.name)
133131

134132
global ns_hotkeys_
135-
options_file = find_options_file()
133+
options_file = platform.find_options_file(app_)
136134
hotkeys = parse_hotkeys(options_file)
137135
hotkeys = map_command_names(hotkeys)
138136
ns_hotkeys_ = namespace_group_hotkeys(hotkeys)
@@ -295,18 +293,6 @@ def deduplicate_hotkeys(hotkeys):
295293
filtered.append(hotkey)
296294
return filtered
297295

298-
def find_options_file():
299-
CSIDL_APPDATA = 26
300-
SHGFP_TYPE_CURRENT = 0
301-
# SHGetFolderPath is deprecated, but SHGetKnownFolderPath is much more cumbersome to use.
302-
# Could just use win32com in that case, to simplify things.
303-
roaming_path_buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
304-
ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, roaming_path_buf)
305-
306-
roaming_path = pathlib.Path(roaming_path_buf.value)
307-
options_path = roaming_path / 'Autodesk' / 'Neutron Platform' / 'Options' / app_.userId / 'NGlobalOptions.xml'
308-
return options_path
309-
310296
def parse_hotkeys(options_file):
311297
hotkeys = []
312298
xml = ET.parse(options_file)

mac.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,32 @@
2121

2222
# Platform-specific code
2323

24+
import pathlib
25+
2426
def fusion_key_to_keyboard_key(key_sequence):
2527
# TODO
2628
keys = key_sequence.split('+')
27-
return key_sequence, keys[-1]
29+
return key_sequence, keys[-1]
30+
31+
def find_options_file(app):
32+
# Seems that Macs can have the files in different locations:
33+
# https://forums.autodesk.com/t5/fusion-360-support/cannot-find-fuision360-documents-locally-in-macos/td-p/8324149
34+
35+
# * /Users/<username>/Library/Application Support/Autodesk
36+
# * /Users/<username>/Library/Containers/com.autodesk.mas.fusion360/Data/Library/Application Support/Autodesk
37+
# append: /Neutron Platform/Options/<user id>\<file.xml>
38+
# Idea: If neededn, check where our add-in is running to determine which path to use.
39+
40+
autodesk_paths = [
41+
pathlib.Path.home() / 'Library/Application Support/Autodesk',
42+
pathlib.Path.home() / 'Library/Containers/com.autodesk.mas.fusion360/Data/Library/Application Support/Autodesk'
43+
]
44+
45+
for autodesk_path in autodesk_paths:
46+
if autodesk_path.exists():
47+
break
48+
else:
49+
raise Exception("Could not find Autodesk directory")
50+
51+
options_path = autodesk_path / 'Neutron Platform' / 'Options' / app.userId / 'NGlobalOptions.xml'
52+
return options_path

windows.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# Platform-specific code
2323

2424
import ctypes
25+
import pathlib
2526

2627
# Virtual Keycodes are available here:
2728
# https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
@@ -93,3 +94,16 @@ def fusion_key_to_vk(fusion_key):
9394
keycode = ret & 0xff
9495
shift_state = ret >> 8
9596
return keycode, shift_state
97+
98+
def find_options_file(app):
99+
CSIDL_APPDATA = 26
100+
SHGFP_TYPE_CURRENT = 0
101+
# SHGetFolderPath is deprecated, but SHGetKnownFolderPath is much more cumbersome to use.
102+
# Could just use win32com in that case, to simplify things.
103+
roaming_path_buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
104+
105+
ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, roaming_path_buf)
106+
107+
roaming_path = pathlib.Path(roaming_path_buf.value)
108+
options_path = roaming_path / 'Autodesk' / 'Neutron Platform' / 'Options' / app.userId / 'NGlobalOptions.xml'
109+
return options_path

0 commit comments

Comments
 (0)