-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.py
More file actions
324 lines (259 loc) · 9.41 KB
/
install.py
File metadata and controls
324 lines (259 loc) · 9.41 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python3
"""
SideWinder Parametric Spline Tool - Cross-Platform Installer for Fusion 360
This installer works on Windows, macOS, and Linux.
It can be run from the command line or double-clicked in most environments.
Usage:
python install.py # Install the add-in
python install.py --remove # Uninstall the add-in
python install.py --help # Show help
"""
import os
import sys
import shutil
import platform
import argparse
from pathlib import Path
def get_fusion_addin_directory():
"""
Get the Fusion 360 Add-Ins directory for the current platform.
Returns:
Path object to the AddIns directory, or None if not found.
"""
system = platform.system()
if system == "Windows":
# Windows: %APPDATA%\Autodesk\Autodesk Fusion 360\API\AddIns
appdata = os.environ.get("APPDATA")
if appdata:
addin_dir = Path(appdata) / "Autodesk" / "Autodesk Fusion 360" / "API" / "AddIns"
return addin_dir
elif system == "Darwin": # macOS
# macOS: ~/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns
home = Path.home()
addin_dir = home / "Library" / "Application Support" / "Autodesk" / "Autodesk Fusion 360" / "API" / "AddIns"
return addin_dir
elif system == "Linux":
# Linux (if Fusion runs via Wine or similar)
# Try common Wine prefixes
home = Path.home()
wine_paths = [
home / ".wine" / "drive_c" / "users" / os.environ.get("USER", "user") / "AppData" / "Roaming" / "Autodesk" / "Autodesk Fusion 360" / "API" / "AddIns",
home / ".local" / "share" / "fusion360" / "AddIns",
]
for path in wine_paths:
if path.exists():
return path
# Return the most likely path even if it doesn't exist
return wine_paths[0]
return None
def get_script_directory():
"""Get the directory containing this script."""
return Path(__file__).parent.resolve()
def print_header(title):
"""Print a formatted header."""
print()
print("=" * 50)
print(f" {title}")
print("=" * 50)
print()
def print_success(message):
"""Print a success message."""
print(f"[OK] {message}")
def print_error(message):
"""Print an error message."""
print(f"[ERROR] {message}")
def print_warning(message):
"""Print a warning message."""
print(f"[WARNING] {message}")
def print_info(message):
"""Print an info message."""
print(f"[INFO] {message}")
def install_addin(force=False):
"""
Install the AxisSpline add-in to Fusion 360.
Args:
force: If True, overwrite existing installation without prompting.
Returns:
True if installation succeeded, False otherwise.
"""
print_header("SideWinder Parametric Spline Tool - Installer for Fusion 360")
# Get directories
script_dir = get_script_directory()
source_dir = script_dir / "AxisSpline"
addin_dir = get_fusion_addin_directory()
# Check source exists
if not source_dir.exists():
print_error("SideWinder (AxisSpline) folder not found!")
print()
print("Please ensure this installer is in the same directory as the AxisSpline folder.")
return False
# Check Fusion 360 directory
if addin_dir is None:
print_error("Could not determine Fusion 360 AddIns directory for this platform.")
print(f"Platform: {platform.system()}")
return False
if not addin_dir.exists():
print_warning("Fusion 360 AddIns directory does not exist.")
print()
print(f"Expected location: {addin_dir}")
print()
print("This could mean:")
print(" - Fusion 360 is not installed")
print(" - Fusion 360 has never been run")
print()
try:
response = input("Would you like to create the directory anyway? (y/n): ").strip().lower()
if response == 'y':
addin_dir.mkdir(parents=True, exist_ok=True)
print_success("Created AddIns directory")
else:
print("Installation cancelled.")
return False
except (EOFError, KeyboardInterrupt):
print("\nInstallation cancelled.")
return False
print_info(f"Source: {source_dir}")
print_info(f"Target: {addin_dir}")
print()
target_dir = addin_dir / "AxisSpline"
# Check for existing installation
if target_dir.exists():
print_warning("SideWinder is already installed.")
print()
if not force:
try:
response = input("Do you want to overwrite the existing installation? (y/n): ").strip().lower()
if response != 'y':
print("Installation cancelled.")
return False
except (EOFError, KeyboardInterrupt):
print("\nInstallation cancelled.")
return False
print()
print_info("Removing existing installation...")
try:
shutil.rmtree(target_dir)
except Exception as e:
print_error(f"Could not remove existing installation: {e}")
print("Please close Fusion 360 and try again.")
return False
# Copy the add-in
print_info("Installing SideWinder Parametric Spline Tool...")
try:
shutil.copytree(source_dir, target_dir)
except Exception as e:
print_error(f"Installation failed: {e}")
return False
# Verify installation
if (target_dir / "AxisSpline.py").exists():
print()
print_header("Installation Successful!")
print(f"SideWinder Parametric Spline Tool has been installed to:")
print(f" {target_dir}")
print()
print("To activate the add-in:")
print(" 1. Open Fusion 360")
print(" 2. Go to Utilities > Add-Ins > Scripts and Add-Ins")
print(" 3. Find 'AxisSpline' in the Add-Ins tab")
print(" 4. Click 'Run' to start the add-in")
print(" 5. Check 'Run on Startup' to auto-load")
print()
print("The tool will appear in the Solid tab under the Create panel.")
return True
else:
print_error("Installation verification failed!")
print("Some files may not have been copied correctly.")
return False
def uninstall_addin():
"""
Uninstall the AxisSpline add-in from Fusion 360.
Returns:
True if uninstallation succeeded, False otherwise.
"""
print_header("SideWinder Parametric Spline Tool - Uninstaller for Fusion 360")
addin_dir = get_fusion_addin_directory()
if addin_dir is None:
print_error("Could not determine Fusion 360 AddIns directory.")
return False
target_dir = addin_dir / "AxisSpline"
if not target_dir.exists():
print_warning("SideWinder is not installed.")
return True
print_info(f"Found installation at: {target_dir}")
print()
try:
response = input("Are you sure you want to uninstall SideWinder? (y/n): ").strip().lower()
if response != 'y':
print("Uninstallation cancelled.")
return False
except (EOFError, KeyboardInterrupt):
print("\nUninstallation cancelled.")
return False
print()
print_info("Removing SideWinder...")
try:
shutil.rmtree(target_dir)
except Exception as e:
print_error(f"Could not remove installation: {e}")
print("Please close Fusion 360 and try again.")
return False
if not target_dir.exists():
print()
print_header("Uninstallation Successful!")
print("SideWinder has been removed from Fusion 360.")
return True
else:
print_error("Uninstallation verification failed!")
return False
def main():
"""Main entry point."""
parser = argparse.ArgumentParser(
description="SideWinder Parametric Spline Tool - Installer for Fusion 360",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python install.py Install the add-in
python install.py --remove Uninstall the add-in
python install.py --force Install without prompts
"""
)
parser.add_argument(
"--remove", "--uninstall",
action="store_true",
help="Uninstall the add-in instead of installing"
)
parser.add_argument(
"--force", "-f",
action="store_true",
help="Force installation without confirmation prompts"
)
parser.add_argument(
"--info",
action="store_true",
help="Show installation directory info and exit"
)
args = parser.parse_args()
if args.info:
addin_dir = get_fusion_addin_directory()
print(f"Platform: {platform.system()}")
print(f"AddIns directory: {addin_dir}")
print(f"Directory exists: {addin_dir.exists() if addin_dir else 'N/A'}")
return 0
try:
if args.remove:
success = uninstall_addin()
else:
success = install_addin(force=args.force)
except KeyboardInterrupt:
print("\n\nOperation cancelled by user.")
return 1
print()
# Pause on Windows if run by double-clicking
if platform.system() == "Windows" and sys.stdin.isatty():
try:
input("Press Enter to exit...")
except (EOFError, KeyboardInterrupt):
pass
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())