Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active August 26, 2016 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oglops/cd8e44df95b24e90f7e6ff8316697a25 to your computer and use it in GitHub Desktop.
Save oglops/cd8e44df95b24e90f7e6ff8316697a25 to your computer and use it in GitHub Desktop.
embed a image browser button into script editor with xml attribute editor template in maya 2015
import maya.cmds as cmds
import maya.utils as mutils
def AEaddImgBrowserModule( plug, uiLabel, annot):
cmds.rowLayout( nc=3 )
cmds.text(l=uiLabel)
p=cmds.textField('imagePathField')
cmds.symbolButton('browser',i="navButtonBrowse.png" )
def AEaddImgBrowserModuleCB( *args ):
from PyQt4.QtGui import QFileDialog
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.AnyFile)
dlg.setFilter("jpg files (*.jpg)")
filename = None
if dlg.exec_():
filename = dlg.selectedFiles()
print 'get file name:',filename,str(filename[0])
if filename and len(filename):
file=str(filename[0])
cmds.setAttr( plug, file,type='string')
cmds.textField(p,e=1,tx=file)
cmds.symbolButton('browser',e=1,c= AEaddImgBrowserModuleCB)
cmds.setParent(u=1)
<?xml version='1.0' encoding='UTF-8'?>
<templates>
<template name="AEtransform">
<attribute name="frameExtension" type="maya.long">
<label>Frame Extension</label>
</attribute>
<attribute name="enumAttr" type="maya.enum">
<label>Enum Attr</label>
</attribute>
<attribute name="imageName" type="maya.string">
<label>Image Name</label>
<description language="cb">py.AEaddImgBrowser.AEaddImgBrowserModule</description>
</attribute>
</template>
<view name="Custom" template="AEtransform">
<property name="frameExtension"/>
<property name="enumAttr"/>
<property name="imageName"/>
</view>
</templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment