-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
90 lines (75 loc) · 3.49 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Utility functions.
#
# This file is part of thomasa88lib, a library of useful Fusion 360
# add-in/script functions.
#
# Copyright (c) 2020 Thomas Axelsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import adsk.core, adsk.fusion, adsk.cam, traceback
import inspect
import os
import re
def short_class(obj):
'''Returns shortened name of Object class'''
return obj.classType().split('::')[-1]
_DEPLOY_FOLDER_PATTERN = re.compile(r'.*/webdeploy/(?:pre-)?production/[^/]+')
def get_fusion_deploy_folder():
'''
Get the Fusion 360 deploy folder.
Typically:
* Windows: C:/Users/<user>/AppData/Local/Autodesk/webdeploy/production/<hash>
* Mac: /Users/<user>/Library/Application Support/Autodesk/webdeploy/production/<hash>
NOTE! The structure within the deploy folder is not the same on Windows and Mac!
E.g. see the examples for get_fusion_ui_resource_folder().
'''
# Strip the suffix from the UI resource folder, i.e.:
# Windows: /Fusion/UI/FusionUI/Resources
# Mac: /Autodesk Fusion 360.app/Contents/Libraries/Applications/Fusion/Fusion/UI/FusionUI/Resources
return _DEPLOY_FOLDER_PATTERN.match(get_fusion_ui_resource_folder()).group(0)
_resFolder = None
def get_fusion_ui_resource_folder():
'''
Get the Fusion UI resource folder. Note: Not all resources reside here.
Typically:
* Windows: C:/Users/<user>/AppData/Local/Autodesk/webdeploy/production/<hash>/Fusion/UI/FusionUI/Resources
* Mac: /Users/<user>/Library/Application Support/Autodesk/webdeploy/production/<hash>/Autodesk Fusion 360.app/Contents/Libraries/Applications/Fusion/Fusion/UI/FusionUI/Resources
'''
global _resFolder
if not _resFolder:
app = adsk.core.Application.get()
_resFolder = app.userInterface.workspaces.itemById('FusionSolidEnvironment').resourceFolder.replace('/Environment/Model', '')
return _resFolder
def get_caller_path():
'''Gets the filename of the file calling the function
that called this function. Used by the library.
That is, is nested in "two steps".
'''
caller_file = os.path.abspath(inspect.stack()[2][1])
return caller_file
def get_file_path():
'''Gets the filename of the function that called this
function.'''
caller_file = os.path.abspath(inspect.stack()[1][1])
return caller_file
def get_file_dir():
'''Gets the directory containing the file which function
called this function.'''
caller_file = os.path.dirname(os.path.abspath(inspect.stack()[1][1]))
return caller_file