aboutsummaryrefslogtreecommitdiff
path: root/install.mel
diff options
context:
space:
mode:
authorMobileMachine\jeremy <[email protected]>2017-07-30 23:02:55 -0700
committerMobileMachine\jeremy <[email protected]>2017-07-30 23:02:55 -0700
commitced8b7bf0bdf7265290984f863d124a5d9c43702 (patch)
treed3e8d80cbcffa838d8b361ad1d7ae16c7ceee7a7 /install.mel
parentMerge pull request #1 from bashuart/patch-1 (diff)
downloadartv2-ced8b7bf0bdf7265290984f863d124a5d9c43702.tar.xz
artv2-ced8b7bf0bdf7265290984f863d124a5d9c43702.zip
Added sample character
Diffstat (limited to 'install.mel')
-rw-r--r--install.mel94
1 files changed, 51 insertions, 43 deletions
diff --git a/install.mel b/install.mel
index 2480931..14ce158 100644
--- a/install.mel
+++ b/install.mel
@@ -1,57 +1,65 @@
-string $scriptLocation=`scriptLocation`;
+// This script installs and loads the ARTv2 plugin, and configures it to load automatically.
+// To run, open the Script Editor and Source the file.
-// Setup module
-python("import os");
-python("home = os.path.expanduser(\"~\")");
+// ---- GLOBAL PROCEDURES ----
-string $mayaModDir = python("home+\"/maya/modules/\"");
-if (`about -os` == "mac") $mayaModDir = python("home+\"/Library/Preferences/Autodesk/maya/modules/\"");
-python("try:\n\tmodDir=os.path.relpath(\""+$scriptLocation+"\",\""+$mayaModDir+"\").replace('\\\\', '/')\nexcept:\n\tmodDir=\"\"");
-string $modDir = python("modDir");
-if ($modDir == "") $modDir = `substring $scriptLocation 1 (size($scriptLocation)-1)`;
+// Dummy procedure used to locate the source script file path
+global proc scriptLocator (){}
+// Return path to directory containing this script
+global proc string scriptLocation ()
+{
+ string $whatIs=`whatIs scriptLocator`;
+ string $fullPath=`substring $whatIs 25 999`; // Strip the human-readable preamble before the file path
+ python("import os"); // Just in case this hasn't been imported already by some other scope
+ return python("os.path.dirname('" + $fullPath + "')");
+}
-string $modName = "ARTv2";
-string $modFileName = $modName+".mod";
-string $modFile = $scriptLocation + "/" + $modFileName;
-string $newModFile = $mayaModDir + $modFileName ;
-string $toBeReplacedStr = "REPLACE_TO_YOUR_PATH";
+// ---- INSTALLATION SCRIPT ----
+string $scriptLocation = scriptLocation();
-int $copySuccess = `sysFile -cp $newModFile $modFile`;
-if (!$copySuccess) sysFile -md $mayaModDir;
+python("import os");
+python("home = os.path.expanduser(\"~\")");
+// Generate platform-relevant path to user's Maya modules directory.
+if (`about -os` == "mac")
+{
+ python("mayaModDir = os.path.join(home, 'Library', 'Preferences', 'Autodesk', 'maya', 'modules'");
+}
+else
+{
+ python("mayaModDir = os.path.join(home, 'maya', 'modules')");
+}
+python("scriptLoc = '" + $scriptLocation + "'");
-$inFileId=`fopen $modFile "r"`;
-$outFileId=`fopen $newModFile "w"`;
-string $nextLine = `fgetline $inFileId`;
+// Attempt to generate relative path to the script, otherwise use the install script's location
+// NB: This is formatted to look like 4 lines, but it's actually a single
+// string containing 2 logical lines manually broken with \n
+python("try:\
+ modDir = os.path.normpath(os.path.relpath(scriptLoc, mayaModDir))\n\
+except:\
+ modDir = scriptLoc");
-while ( size( $nextLine ) > 0 ) {
- $nextLine = `substitute $toBeReplacedStr $nextLine $modDir`;
- fprint($outFileId, $nextLine);
- $nextLine = `fgetline $inFileId`;
-}
-fclose $inFileId;
-fclose $outFileId;
+// Set up names and paths for generating the module file
+python("modName = 'ARTv2'");
+python("modFileName = modName + '.mod'");
+python("modFile = os.path.join(scriptLoc, modFileName)");
+python("newModFile = os.path.join(mayaModDir, modFileName)");
+python("replace_str = 'REPLACE_TO_YOUR_PATH'");
+// Create new module file from template
+python("if not os.path.exists(mayaModDir): os.path.makedirs(mayaModDir)");
+python("with open(modFile, 'r') as f: template = f.read()");
+python("with open(newModFile, 'w') as f: f.write(template.replace(replace_str, modDir))");
-// load script path for current session
-loadModule -a;
-loadPlugin "ARTv2";
-pluginInfo -edit -autoload true "ARTv2";
+// Load plugin and set to auto-load
-// Helper functions for locating script's location
-global proc scriptLocator (){}
+loadModule -ld `python("newModFile")`;
-global proc string scriptLocation ()
-{
- string $whatIs=`whatIs scriptLocator`;
- string $fullPath=`substring $whatIs 25 999`;
- string $buffer[];
- int $numTok=`tokenize $fullPath "/" $buffer`;
- int $numLetters=size($fullPath);
- int $numLettersLastFolder=size($buffer[$numTok-1]);
- string $scriptLocation=`substring $fullPath 1 ($numLetters-$numLettersLastFolder)`;
- return $scriptLocation;
-} \ No newline at end of file
+string $result = `confirmDialog -title "ARTv2" -message "ARTv2 installed! Maya will now close.\nPlease restart Maya \
+and load the ARTv2 plugin\n(set auto-load as well!) and follow the prompts."
+ -button "Finish"`;
+
+quit -force; \ No newline at end of file