Skip to content

Instantly share code, notes, and snippets.

@dgovil
Created May 4, 2017 05:39
Show Gist options
  • Save dgovil/8444b270cbbd04f365b27ef18e651258 to your computer and use it in GitHub Desktop.
Save dgovil/8444b270cbbd04f365b27ef18e651258 to your computer and use it in GitHub Desktop.
A simple installer script to install simplex by Blur. Simply run this in Python in maya
from maya import cmds as mc
import urllib2
import os
import zipfile
import shutil
def downloadRelease():
userTmpDir = mc.internalVar(userTmpDir=True)
dest = os.path.join(userTmpDir, 'simplex.zip')
if os.path.exists(dest):
mc.warning("Download already exists at %s. Not redownloading." % dest)
return dest
with open(dest, 'wb') as f:
f.write(urllib2.urlopen('https://github.com/blurstudio/Simplex/releases/download/1.0.3/Simplex.zip').read())
mc.warning("Download Complete! Downloaded to %s" % dest)
return dest
def extract(filepath):
mc.warning("Extracting file")
scriptDir = mc.internalVar(userScriptDir=True)
target = os.path.join(scriptDir, 'Simplex')
if os.path.exists(target):
mc.warning("Simplex is already extracted here: %s" % target)
return target
with zipfile.ZipFile(filepath, 'r') as z:
z.extractall(scriptDir)
if not os.path.exists(target):
mc.error("Could not find the Simplex directory at %s" % target)
mc.warning("Extracted Simplex to %s" % target)
return target
def moveMod(location):
modFile = os.path.join(location, 'simplex.mod')
scriptDir = mc.internalVar(userScriptDir=True)
modDir = os.path.join(os.path.dirname(os.path.dirname(scriptDir)), 'modules')
target = os.path.join(modDir, 'simplex.mod')
if os.path.exists(target):
mc.warning("Mod file already exists here %s. Not Overwriting" % target)
return target
if not os.path.exists(modFile):
mc.error("The modfile doesn't exist here: %s" % modFile)
if not os.path.exists(modDir):
mc.warning("Creating modules directory: %s" % modDir)
os.mkdir(modDir)
shutil.copy2(modFile, target)
return target
def changeMod(mod, location):
with open(mod, 'r') as f:
contents = f.read()
contents = contents.replace('<FILEPATH>', location)
with open(mod, 'w') as f:
f.write(contents)
mc.warning("Wrote changes to modfile")
def loadPlugin(location):
version = mc.about(version=True)
plugin = os.path.join(location, 'maya%s/plug-ins' % version, 'simplex_maya.mll')
if not os.path.exists(plugin):
mc.error("Could not find plugin here %s" % plugin)
mc.loadPlugin(plugin)
def moveUI(location):
uiDir = os.path.join(location, 'SimplexUI')
scriptDir = mc.internalVar(userScriptDir=True)
target = os.path.join(scriptDir, 'SimplexUI')
if not os.path.exists(target):
mc.warning("Copying SimplexUI to scripts directory so it can be imported")
shutil.copytree(uiDir, target)
return target
def run():
from SimplexUI import runSimplexUI
runSimplexUI()
def main():
download = downloadRelease()
location = extract(download)
mod = moveMod(location)
changeMod(mod, location)
loadPlugin(location)
moveUI(location)
run()
mc.confirmDialog(title="Restart Maya", message=(
"You may need to restart maya and then load the simplex_maya.mll plugin\n"
"Then run this in python:\n\n"
"from SimplexUI import runSimplexUI\n"
"runSimplexUI()"
)
)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment