1+ import os
2+ import sys
3+ import ctypes
4+ import subprocess
5+
6+ def run_as_admin ():
7+ """Run script with admin privileges"""
8+ if ctypes .windll .shell32 .IsUserAnAdmin ():
9+ return True
10+
11+ # Re-run with admin privileges
12+ script = os .path .abspath (sys .argv [0 ])
13+ params = ' ' .join ([script ] + sys .argv [1 :])
14+ ctypes .windll .shell32 .ShellExecuteW (None , "runas" , sys .executable , params , None , 1 )
15+ sys .exit ()
16+
17+ def find_blender_addons_path ():
18+ """Find Blender's addons directory"""
19+ username = os .getenv ('USERNAME' )
20+ if not username :
21+ print ("Failed to get current username" )
22+ return None
23+
24+ # Try to locate Blender's addons path
25+ base_path = f"C:\\ Users\\ { username } \\ AppData\\ Roaming\\ Blender Foundation\\ Blender"
26+ if not os .path .exists (base_path ):
27+ print (f"Blender config directory not found: { base_path } " )
28+ return None
29+
30+ # Find the latest Blender version
31+ versions = [d for d in os .listdir (base_path ) if os .path .isdir (os .path .join (base_path , d ))]
32+ if not versions :
33+ print ("No Blender version directories found" )
34+ return None
35+
36+ # Sort versions and pick the newest
37+ versions .sort (reverse = True )
38+ latest_version = versions [0 ]
39+
40+ addons_path = os .path .join (base_path , latest_version , "scripts" , "addons" )
41+ if not os .path .exists (addons_path ):
42+ print (f"Addons directory not found: { addons_path } " )
43+ return None
44+
45+ return addons_path
46+
47+ def create_symbolic_link ():
48+ """Create symbolic link with user confirmation"""
49+ # Get current directory
50+ current_dir = os .path .dirname (os .path .abspath (__file__ ))
51+ source_folder = os .path .join (current_dir , "io_mesh_w3d" )
52+
53+ if not os .path .exists (source_folder ):
54+ print (f"Source folder not found: { source_folder } " )
55+ return False
56+
57+ # Get Blender addons path
58+ addons_path = find_blender_addons_path ()
59+ if not addons_path :
60+ return False
61+
62+ target_path = os .path .join (addons_path , "io_mesh_w3d" )
63+
64+ # Check if target already exists
65+ if os .path .exists (target_path ):
66+ print (f"Target path already exists: { target_path } " )
67+ return False
68+
69+ # Prepare command and display for confirmation
70+ cmd = f'mklink /D "{ target_path } " "{ source_folder } "'
71+ print ("\n About to execute the following command:" )
72+ print (f" { cmd } \n " )
73+
74+ # Get user confirmation
75+ confirm = input ("Do you want to proceed? (y/n): " ).strip ().lower ()
76+ if confirm != 'y' :
77+ print ("Operation cancelled by user" )
78+ return False
79+
80+ # Create symbolic link
81+ try :
82+ subprocess .run (cmd , shell = True , check = True )
83+ print (f"\n Successfully created symbolic link: { target_path } -> { source_folder } " )
84+ return True
85+ except subprocess .CalledProcessError as e :
86+ print (f"\n Failed to create symbolic link: { e } " )
87+ return False
88+
89+ if __name__ == "__main__" :
90+ # Request admin privileges
91+ run_as_admin ()
92+
93+ # Execute main logic
94+ print ("\n Blender Addon Symbolic Link Creator" )
95+ print ("----------------------------------" )
96+
97+ if create_symbolic_link ():
98+ print ("\n Operation completed successfully!" )
99+ else :
100+ print ("\n Operation failed" )
101+
102+ # Keep window open
103+ input ("\n Press Enter to exit..." )
0 commit comments