Hello! I would like to know if there’s a way in python to install self buttons in maya from the installation folder to maya directly.
So could install my shelf from whatever folder i use on the disk.
I think advanced skeleton does that, we have a ‘intall.mel’ that we can drag and drop in maya then it intalls all the shelves needed.
This basically generates a mod and shelf file in the folder i dragged the script from. The onMayaDroppedPythonFile is a hard coded Maya thing you need for the drag drop mechanic to work. I then put the mod/shelf files in the appropriate location. You could however have it save it in the right path, or edit the env file etc… lots of ways to do it. For me this was the cleanest way i found - generate the mod file but allow the user to place it in the right location.
Hello! Thank you soo much for the exemple!! Great help. I was a bit confused about not seing the shelf first but i understood why! I can see the effect now!! This is exactly what i needed to know. Strange thing is that i struggle to find usefull info on this! Should pin this topic ^^!
I tried different approach and found it work without problem!
suggestions are welcome
import os
import shutil
import maya.cmds as cmds
import maya.mel as mel
def onMayaDroppedPythonFile(*args):
try:
# Script directory for where file come from, script_file_path for full address
# Make sure this code is on the same location with the script
installer_directory = os.path.dirname(__file__)
script_file_path = os.path.join(installer_directory, "file_name.py)
# raise runtime error if script not found
if not os.path.exists(script_file_path):
raise RuntimeError("Unable to find '"file_name.py"' relative to this installer file")
# Get default script directory for suggestion
prefs_dir = os.path.dirname(cmds.about(preferences=True))
scripts_dir = os.path.normpath(os.path.join(prefs_dir, "scripts"))
# copy script to maya default directory
shutil.copy(script_file_path,scripts_dir)
# Generate Shelf for current active shelf
current_shelf = mel.eval("string $currentShelf = `tabLayout -query -selectTab $gShelfTopLevel`;")
cmds.setParent(current_shelf)
cmds.shelfButton(command="import script_name; script_name.execute()",ann="script_name",
label="script_name",image="custom.png",sourceType="python",iol="SCRIPT_NAME")
cmds.confirmDialog(message="Script successfully installed ""<br>""<br>""{0}".format(scripts_dir),
title="Confirmation dialog")
except Exception as e:
cmds.confirmDialog(message="Script failed to installed: {0}".format(e),icon = "warning",title="ERROR")