Asset Browser with dynamic UI - Creating a new scene breaks UI

48 views
Skip to first unread message

dur

unread,
Sep 6, 2018, 8:39:38 AM9/6/18
to Python Programming for Autodesk Maya
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))



Justin Israel

unread,
Sep 10, 2018, 5:48:48 PM9/10/18
to python_in...@googlegroups.com
Did you end up figuring this out? You listed a lot of unwanted behaviours happening, at all once. I am not sure why your UI would clear when you create a new scene. You do seem to be using a relative root TMPDIR path, so I am not sure of your cwd is changing over time making these paths invalid. 

--
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_m...@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.

Michael Boon

unread,
Sep 10, 2018, 8:44:57 PM9/10/18
to Python Programming for Autodesk Maya
Just a guess: you seem to be relying on Maya's UI context when you create your layout in listFiles. I mean, you delete any existing scrollLayout, then you create a new one, but I don't see anything that ensures the new scrollLayout will be created in your window. If Maya has created new UIs since you created your window, your layout is likely to be created in those instead.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Martin Durhuus

unread,
Sep 11, 2018, 3:39:18 AM9/11/18
to python_in...@googlegroups.com
I think you're pretty spot on Michael. It seems Maya was refreshing it's own windows, and my stuff was getting attached. I was to blame, but that hierarchical ui parenting, I can't say I'm a fan of. I actually ended up switching it to Qt and doing it much more rigid and explicit, and it works quite well with extending a QListWidget there. :)

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
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+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages