krathjen / studiolibrary

Studio Library
https://www.studiolibrary.com
GNU Lesser General Public License v3.0
352 stars 140 forks source link

How to open Studio Library on Maya Startup? #414

Open asuarefaem opened 1 year ago

asuarefaem commented 1 year ago

Hello. When I close Maya with plugins like MG Picker Studio or Tweener open, they will auto run when I open Maya. Studio Library won't. So, is it possible to Maya Studio Library run on Maya startup? I tried usersetup but it hasn't worked yet.

gabrieljreed commented 1 year ago

You might try wrapping it in a cmds.evalDeferred block inside your userSetup.py

import maya.cmds as mc
mc.evalDeferred("""
import studiolibrary
studiolibrary.main()
""")

This is because userSetup.py executes when Maya starts up, not when the window is ready. Putting it inside an evalDeferred block forces it to wait until the window has fully loaded. Hope this helps!

adevra commented 9 months ago
import sys
import maya.cmds as cmds

# Path to the 'src' directory where Studio Library's Python package is located
studio_lib_path = 'C:/Users/username/Documents/maya/2022/scripts/studiolibrary-2.14.1/src'

# Ensure this path is in sys.path
if studio_lib_path not in sys.path:
    sys.path.insert(0, studio_lib_path)

def init_studio_library():
    try:
        import studiolibrary
        studiolibrary.main()
    except Exception as e:
        print("Failed to initialize Studio Library:", e)

# Using scriptJob to defer execution
cmds.scriptJob(runOnce=True, idleEvent=init_studio_library)