I want to create a custom shelf at startup in Maya 2018. I am calling a script to build the shelf in a userSetup.py file. The script will create the shelf if run in the script editor after launch, but throws an error when called on startup.
#userSetup.py
#-----
import maya.cmds as cmds
import sys
sys.path.append('/Users/alfredwinters/Desktop/python/scripts/')
import lighting_tools_shelf
cmds.evalDeferred("lighting_tools_shelf")
#lighting_tools_shelf.py
#----
import maya.cmds as cmds
cmds.shelfLayout("lighting_shelf", p="ShelfLayout")
This is the error I get when calling the script at launch.
Failed to execute userSetup.py
Traceback (most recent call last):
File "/Users/alfredwinters/Library/Preferences/Autodesk/maya/2018/scripts/userSetup.py", line 8, in import lighting_tools_shelf
File "/Users/alfredwinters/Desktop/python/scripts/lighting_tools_shelf.py", line 19, in custom_shelf cmds.shelfLayout(name, p="ShelfLayout")
RuntimeError: shelfLayout: Object 'ShelfLayout' not found.
As you have not mentioned the error while calling cmds.shelfLayout(name, p="ShelfLayout")
RuntimeError: shelfLayout: Object 'ShelfLayout' not found.
It simply saying the ShelfLayout object is not available in the given context. The ShelfLayout represents the main layout holding all the Maya Shelves. But it should not be used as it is. You should have to get it from the global variables.
Example:
import maya.mel as mel
main_shelf = mel.eval('$tempMelVar=$gShelfTopLevel')
# Now main_shelf holds complete path the the layout
# Now you can use it as parent for other shelf layouts
cmds.shelfLayout(name, p=main_shelf)
Hope this will resolve your issue. Thanks