aboutsummaryrefslogtreecommitdiff
path: root/install.mel
blob: f62302f09bd9b35716bc3a9dcb2b0ee51953740d (plain) (blame)
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
// This procedue is a dummy procedure that will have whatIs run on it to determine where it was run from.
global proc locate_script(){}

// Run whatIs on our dummy procedure to determine where the script location is.
global proc string script_location ()
{
    string $whatIs = `whatIs locate_script`;
    string $buffer[];
    string $num_tokens = `tokenize $whatIs " " $buffer`;
    return $buffer[4];
}

// Get the script location.
string $script_path = script_location();

// Find maya module directory based on operating system.
python("import os");
python("home = os.path.expanduser(\"~\")");

if (`about -os` == "mac")
{
    python("maya_module_directory = os.path.join(home, 'Library', 'Preferences', 'Autodesk', 'maya', 'modules')");
}
else
{
    python("maya_module_directory = os.path.join(home, 'maya', 'modules')");
}

// This is the default maya module directory location.
python("maya_module_directory = os.path.normpath(maya_module_directory)");

// Find the relative path of the script in relation to the maya module directory.
python("script_loc = os.path.dirname('" + $script_path + "'" + ")");

python("try:\
    mod_dir = os.path.normpath(os.path.relpath(script_loc, maya_module_directory))\n\
except:\
    mod_dir = script_loc");

// Build relevant path data for creating the module file
python("mod_name = 'ARTv2'");
python("mod_file_name = mod_name + '.mod'");
python("mod_file = os.path.join(script_loc, mod_file_name)");
python("new_mod_file = os.path.join(maya_module_directory, mod_file_name)");
python("replace_string = 'REPLACE_TO_YOUR_PATH'");

// Create new module file from the template file.
python("if not os.path.exists(maya_module_directory): os.makedirs(maya_module_directory)");
python("with open(mod_file, 'r') as f: template = f.read()");
python("with open(new_mod_file, 'w') as f: f.write(template.replace(replace_string, mod_dir))");

// Load the plug-in.


python("import json");
python("module_paths = os.environ['MAYA_PLUG_IN_PATH']");
python("module_paths += ';'");
python("module_paths += os.path.join(script_loc, 'plug-ins')");
python("os.environ['MAYA_PLUG_IN_PATH'] = module_paths");
rehash;
loadPlugin "artv2.py";
pluginInfo -edit -autoload 1 "artv2.py";
// Report to user
string $result = `confirmDialog -title "ARTv2" -message "ARTv2 has been installed." -button "Finish"`;