userSetup.py set up?

userSetup.py set up?

cubmask
Observer Observer
7,659 Views
1 Reply
Message 1 of 2

userSetup.py set up?

cubmask
Observer
Observer

Hi Team,

 

Could you please help me here. I am working with Maya 2023 on macOS Monterey. I am trying to install Unreal ARTv1, code below. I have been scouring the forum for answers on two question.

 

1. In Maya 2023, there is no userSetup.py in the and I am trying to set up from scratch. What directory should I save the the file so Maya executes it at startup? I have tried the following directories but no luck:

  • /Users/kevincoker/Library/Preferences/Autodesk/maya/2023/scripts

  • /Users/kevincoker/Library/Preferences/Autodesk/maya/2023

  • /Users/kevincoker/Library/Preferences/Autodesk/maya/scripts

2. Could I get advise on my userSetup.py script, from what I have observed the code is consise to what is expected.

 

import maya.cmds as cmds
import os
import sys
from functools import partial
import maya.mel as mel

MAYA_SEP = '/'

def correctSysPath():
    for i, path in enumerate(sys.path):
        if path[-1] in (MAYA_SEP, os.sep, os.altsep):
            sys.path[i] = sys.path[i][:-1]

correctSysPath()

def deleteOldAutoSaves():
    import maya.cmds as cmds
    import time
    import os.path, time
    
    
    save = cmds.autoSave(q = True, enable = True)
    destDir = cmds.autoSave(q = True, destinationFolder = True)
    deleteDays = 3
    
    if save:
        now = time.time()
        fileCap = now - 60*60*24*deleteDays
    
        files = os.listdir(destDir)
        
        for file in files:
            fileCreation = os.path.getctime(os.path.join(destDir, file))
            if fileCreation < fileCap:
                os.remove(os.path.join(destDir, file))
                
                
def mayaToolsInstall_UI():
    
    if cmds.window("mayaToolsInstall_UI", exists = True):
        cmds.deleteUI("mayaToolsInstall_UI")
        
    window = cmds.window("mayaToolsInstall_UI", w = 300, h = 100, title = "Maya Tools Install", mnb = False, mxb = False)
    
    mainLayout = cmds.columnLayout(w = 300, h = 100)
    formLayout = cmds.formLayout(w = 300, h = 100)
    
    text = cmds.text(label = "ERROR: Could not find Maya Tools directory.\n Please locate folder using the \'Browse\' button.", w = 300)
    cancelButton = cmds.button(label = "Cancel", w = 140, h = 50, c = mayaToolsInstall_Cancel)
    browseButton = cmds.button(label = "Browse", w = 140, h = 50, c = mayaToolsInstall_Browse)
    
    cmds.formLayout(formLayout, edit = True, af = [(text, 'left', 10), (text, 'top', 10)])
    cmds.formLayout(formLayout, edit = True, af = [(cancelButton, 'left', 5), (cancelButton, 'top', 50)])
    cmds.formLayout(formLayout, edit = True, af = [(browseButton, 'right', 5), (browseButton, 'top', 50)])
    
    cmds.showWindow(window)
    cmds.window(window, edit = True, w = 300, h = 100)
    
    
    
def mayaToolsInstall_Cancel(*args):
    
    cmds.deleteUI("mayaToolsInstall_UI")
    cmds.warning("Maya Tools will not be setup")
    


def mayaToolsInstall_Browse(*args):
    
    mayaToolsDir = cmds.fileDialog2(dialogStyle = 2, fileMode = 3)[0]

    #confirm that this is actually the maya tools directory
    if mayaToolsDir.rpartition("/")[2] != "MayaTools":
        cmds.warning("Selected directory is not valid. Please locate the MayaTools directory.")
        
        
    else:
        cmds.deleteUI("mayaToolsInstall_UI")
        
        #create file that contains this path
        path = cmds.internalVar(usd = True) + "mayaTools.txt"
        
        f = open(path, 'w')
        f.write(mayaToolsDir)
        f.close()
        
        
        #run setup
        cmds.file(new = True, force = True)
        
        
        
def mayaTools():
    
    #import custom maya setup script
    print cmds.internalVar(usd = True)
    print cmds.internalVar(upd = True)
    path = cmds.internalVar(usd = True)
    path = path + "mayaTools.txt"
    print path
    
    if os.path.exists(path):
        f = open(path, 'r')
        
        mayaToolsDir = f.readline()
        if not os.path.exists(mayaToolsDir):
            mayaToolsInstall_UI()
        
        path = mayaToolsDir + "/General/Scripts"
        pluginPath = mayaToolsDir + "/General/Plugins"
        
        #look in sys.path to see if path is in sys.path. if not, add it
        if not path in sys.path:
            sys.path.append(path)
            
            
        #run setup
        import customMayaMenu as cmm
        cmm.customMayaMenu()
        cmds.file(new = True, force = True)
    
    
    else:
        mayaToolsInstall_UI()
        
        

#setup script jobs
scriptJobNum2 = cmds.scriptJob(event = ["NewSceneOpened", mayaTools])

 

 

 

Thanks in advance

0 Likes
7,660 Views
1 Reply
Reply (1)
Message 2 of 2

michael--n
Explorer
Explorer

your userSetup.py should run from one of those ".../scripts" locations, according to this:

https://help.autodesk.com/view/MAYAUL/2023/ENU/?guid=GUID-640C1383-3FB8-410F-AE18-987A812B5914

 

It might be that your script is failing to execute rather than it not loading. Try opening the output window to see. Unhandled exceptions will appear there as the userSetup.py runs before the main maya window has loaded:
https://help.autodesk.com/view/MAYAUL/2023/ENU/?guid=GUID-D13AA354-01ED-4B20-95A2-E90E03275992

Print statements get sent there too, so you can put one of those in to check if the file is being picked up or not.

 

Lastly that last line, do you want the UI to open up every time a new scene is loaded up? If so that's fine, but if not I'd recommend using something like maya.cmds.evalDeferred  or maya.utils.executeDeferred

0 Likes