Discussion:
[Maya-Python] Asset Browser with dynamic UI - Creating a new scene breaks UI
dur
2018-09-06 12:39:38 UTC
Permalink
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))
--
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.
Justin Israel
2018-09-10 21:48:34 UTC
Permalink
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.
Post by dur
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 :)
TMPDIR = "some/initial/dir"
listFiles(os.path.dirname(in_dir), layout_id)
print("Accessed parent dir: " + os.path.dirname(in_dir) + " with layout: "
+ layout_id)
listFiles('/'.join([in_dir, dir_name]), layout_id)
print("Accessed child dir: " + '/'.join([in_dir, dir_name]) + " with
layout: " + layout_id)
'''List files(.fbx) and folders in a given layout'''
#Refresh layouts with correct files/folders
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')
#print("dir: " + d)
cmds.button(label=d, bgc=(0.749, 0.647, 0.411), command=partial(childDirectory,
d, in_dir, layout_id))
#print("fbx: " + fbx)
cmds.button(label=fbx, bgc=(0.411, 0.749, 0.525), command=partial(importFbx,
fbx, in_dir))
'''Imports fbx for editing, given path'''
path = '/'.join([in_dir, fbx_name])
cmds.file(path, type="FBX", i=True)
checkOut(path)
'''Initialize plugin with base path and base UI'''
#Default check to avoid duplicate windows
winID = 'main'
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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/CAPGFgA0iNaPSrjDGfM5-gOqbujD2FGGLz%3DPQFk06vu6y-mfzCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Michael Boon
2018-09-11 00:44:56 UTC
Permalink
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.
Post by Justin Israel
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.
Post by dur
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 :)
TMPDIR = "some/initial/dir"
listFiles(os.path.dirname(in_dir), layout_id)
" + layout_id)
listFiles('/'.join([in_dir, dir_name]), layout_id)
print("Accessed child dir: " + '/'.join([in_dir, dir_name]) + " with
layout: " + layout_id)
'''List files(.fbx) and folders in a given layout'''
#Refresh layouts with correct files/folders
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')
#print("dir: " + d)
cmds.button(label=d, bgc=(0.749, 0.647, 0.411), command=partial(childDirectory,
d, in_dir, layout_id))
#print("fbx: " + fbx)
cmds.button(label=fbx, bgc=(0.411, 0.749, 0.525), command=partial(importFbx,
fbx, in_dir))
'''Imports fbx for editing, given path'''
path = '/'.join([in_dir, fbx_name])
cmds.file(path, type="FBX", i=True)
checkOut(path)
'''Initialize plugin with base path and base UI'''
#Default check to avoid duplicate windows
winID = 'main'
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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/c4961986-7221-4bfb-bf37-2857e585c4d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin Durhuus
2018-09-11 07:39:13 UTC
Permalink
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. :)
Post by Michael Boon
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.
Post by Justin Israel
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.
Post by dur
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 :)
TMPDIR = "some/initial/dir"
listFiles(os.path.dirname(in_dir), layout_id)
print("Accessed parent dir: " + os.path.dirname(in_dir) + " with
layout: " + layout_id)
listFiles('/'.join([in_dir, dir_name]), layout_id)
print("Accessed child dir: " + '/'.join([in_dir, dir_name]) + " with
layout: " + layout_id)
'''List files(.fbx) and folders in a given layout'''
#Refresh layouts with correct files/folders
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')
#print("dir: " + d)
cmds.button(label=d, bgc=(0.749, 0.647, 0.411), command
=partial(childDirectory, d, in_dir, layout_id))
#print("fbx: " + fbx)
cmds.button(label=fbx, bgc=(0.411, 0.749, 0.525), command=partial(importFbx,
fbx, in_dir))
'''Imports fbx for editing, given path'''
path = '/'.join([in_dir, fbx_name])
cmds.file(path, type="FBX", i=True)
checkOut(path)
'''Initialize plugin with base path and base UI'''
#Default check to avoid duplicate windows
winID = 'main'
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
To view this discussion on the web visit https://groups.google.com/d/ms
gid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%
40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/ddb59f28-9eff-4f65-9d0e-8d9e7a23d950%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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
To view this discussion on the web visit https://groups.google.com/d/
msgid/python_inside_maya/c4961986-7221-4bfb-bf37-
2857e585c4d3%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/c4961986-7221-4bfb-bf37-2857e585c4d3%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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/CABHuVDPT3TBvxo3vqqcmRAnF-hZOrjbxiunvEiKFASKs4Na0zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...