dur
2018-09-06 12:39:38 UTC
Hello all!
So I'm creating an asset browser to filter folders and fbx files, using
native Maya UI. I'm basically listing folders and files in a path as
buttons, and assigning partial functions to each. Jumping between
directories works just fine, as I initially run the script from the Script
Editor. However, if I create a new scene, or click on an fbx(importing it),
the content of the UI either disappears, does not react or brings me to a
wrong folder. I was printing out the current directories and layout id, and
it seems to be in order. So I'm quite stuck with what is happening, as I'm
not really sure what's being changed when the scene changes.
any pointers or help would really be appreciated :)
Here's the code:
TMPDIR = "some/initial/dir"
def parentDirectory(in_dir, layout_id, *args):
listFiles(os.path.dirname(in_dir), layout_id)
print("Accessed parent dir: " + os.path.dirname(in_dir) + " with layout: "
+ layout_id)
def childDirectory(dir_name, in_dir, layout_id, *args):
listFiles('/'.join([in_dir, dir_name]), layout_id)
print("Accessed child dir: " + '/'.join([in_dir, dir_name]) + " with
layout: " + layout_id)
def listFiles(in_dir, layout_id):
'''List files(.fbx) and folders in a given layout'''
#Refresh layouts with correct files/folders
if cmds.scrollLayout(layout_id, exists=True):
cmds.deleteUI(layout_id)
cmds.scrollLayout(layout_id, hst=0)
cmds.columnLayout()
cmds.button(label='..', bgc=(0.682, 0.564, 0.298), command=partial(
parentDirectory, in_dir, layout_id))
dirs = cmds.getFileList(folder=in_dir, filespec='*.')
files = cmds.getFileList(folder=in_dir, filespec='*.fbx')
for d in dirs:
#print("dir: " + d)
cmds.button(label=d, bgc=(0.749, 0.647, 0.411), command=partial(childDirectory,
d, in_dir, layout_id))
for fbx in files:
#print("fbx: " + fbx)
cmds.button(label=fbx, bgc=(0.411, 0.749, 0.525), command=partial(importFbx,
fbx, in_dir))
def importFbx(fbx_name, in_dir, *args):
'''Imports fbx for editing, given path'''
path = '/'.join([in_dir, fbx_name])
cmds.file(path, type="FBX", i=True)
checkOut(path)
def initPlugin():
'''Initialize plugin with base path and base UI'''
#Default check to avoid duplicate windows
winID = 'main'
if cmds.window(winID, exists=True):
cmds.deleteUI(winID)
cmds.window(winID, title="Asset Browser", sizeable=True)
browserLayout = 'browserID'
cmds.scrollLayout(browserLayout, hst=0)
cmds.columnLayout()
listFiles(TMPDIR, browserLayout)
cmds.showWindow(winID)
cmds.window(winID, edit=True, widthHeight=(400, 400))
So I'm creating an asset browser to filter folders and fbx files, using
native Maya UI. I'm basically listing folders and files in a path as
buttons, and assigning partial functions to each. Jumping between
directories works just fine, as I initially run the script from the Script
Editor. However, if I create a new scene, or click on an fbx(importing it),
the content of the UI either disappears, does not react or brings me to a
wrong folder. I was printing out the current directories and layout id, and
it seems to be in order. So I'm quite stuck with what is happening, as I'm
not really sure what's being changed when the scene changes.
any pointers or help would really be appreciated :)
Here's the code:
TMPDIR = "some/initial/dir"
def parentDirectory(in_dir, layout_id, *args):
listFiles(os.path.dirname(in_dir), layout_id)
print("Accessed parent dir: " + os.path.dirname(in_dir) + " with layout: "
+ layout_id)
def childDirectory(dir_name, in_dir, layout_id, *args):
listFiles('/'.join([in_dir, dir_name]), layout_id)
print("Accessed child dir: " + '/'.join([in_dir, dir_name]) + " with
layout: " + layout_id)
def listFiles(in_dir, layout_id):
'''List files(.fbx) and folders in a given layout'''
#Refresh layouts with correct files/folders
if cmds.scrollLayout(layout_id, exists=True):
cmds.deleteUI(layout_id)
cmds.scrollLayout(layout_id, hst=0)
cmds.columnLayout()
cmds.button(label='..', bgc=(0.682, 0.564, 0.298), command=partial(
parentDirectory, in_dir, layout_id))
dirs = cmds.getFileList(folder=in_dir, filespec='*.')
files = cmds.getFileList(folder=in_dir, filespec='*.fbx')
for d in dirs:
#print("dir: " + d)
cmds.button(label=d, bgc=(0.749, 0.647, 0.411), command=partial(childDirectory,
d, in_dir, layout_id))
for fbx in files:
#print("fbx: " + fbx)
cmds.button(label=fbx, bgc=(0.411, 0.749, 0.525), command=partial(importFbx,
fbx, in_dir))
def importFbx(fbx_name, in_dir, *args):
'''Imports fbx for editing, given path'''
path = '/'.join([in_dir, fbx_name])
cmds.file(path, type="FBX", i=True)
checkOut(path)
def initPlugin():
'''Initialize plugin with base path and base UI'''
#Default check to avoid duplicate windows
winID = 'main'
if cmds.window(winID, exists=True):
cmds.deleteUI(winID)
cmds.window(winID, title="Asset Browser", sizeable=True)
browserLayout = 'browserID'
cmds.scrollLayout(browserLayout, hst=0)
cmds.columnLayout()
listFiles(TMPDIR, browserLayout)
cmds.showWindow(winID)
cmds.window(winID, edit=True, widthHeight=(400, 400))
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.