The selection on the scrollList, I think, is a list. So passing its value
directly to the cmds.image() would be wrong since it wants only a single string.
If what you are trying now gives you a specific problem, let us know so we can
look at that actual code for that one area.
Once quick suggestion is that you might want to just pass the callable object
directly to your buttons instead of using strings that have to be evaluated.
cmds.button(label='Open File',c=oFile)
cmds.button(label='Import File',c=impFile)
cmds.button(label='Reference File',c=refFile)
cmds.button(label='Open Directory',c=openBrowser)
Of course, this code would have to also be in a function (like a main() or
something) so that it executes after all the function definitions have been
created. You shouldn't have loose code like that running in the global scope.
It prevents your script from ever being able to be imported by another tool to
reuse functionality.
def main():
# do stuff
and then in some other code:
import myScript
myScript.main()
On Jun 9, 2012, at 10:56 AM, Matias Volonte wrote:
> thanks Justin, I am testing your suggestion I will see if I can make it work.
> Here is part of the code in case you would like to actually see what I am
> trying to do, if you have more suggestions please let me know, thanks.
>
>
>
> import os
> import sys
> import maya.cmds as cmds
> import maya.mel as mel
> import subprocess
>
>
> window = cmds.window(title='Assets Browser')
>
> cmds.columnLayout(adj=True)
> cmds.rowColumnLayout(nc=4)
>
> cmds.button(label='Open File',c='oFile()')
> cmds.button(label='Import File',c='impFile()')
> cmds.button(label='Reference File',c='refFile()')
> cmds.button(label='Open Directory',c='openBrowser()')
> cmds.setParent( '..' )
> cmds.setParent( '..' )
> cmds.setParent( '..' )
>
> cmds.rowColumnLayout(numberOfColumns=3)
> cmds.text(label='Assets Directory')
> cmds.text(label='Maya Files')
> cmds.text(label='File Info')
>
> cmds.textScrollList("dirs",w=120)
> cmds.textScrollList("filesList",sc='images()',w=120)
> cmds.textScrollList('perico')
> '''
>
> Here is the problem
> #cmds.image(image=imgages())
>
> If I create a function that returns the path to an image, everything works
> great. On the other hand If I pass the path
> using the selection on the textScrollList, it does not work
>
> '''
>
> cmds.setParent( '..' )
>
>
> cmds.setParent( '..' )
> cmds.showWindow( window )
>
> def populate():
>
> assets ='Cars','Trees','Furniture'
>
> cmds.textScrollList('dirs',e=True,sc='assetsList()',fn='boldLabelFont',si=True,append=assets)
>
>
>
> def images():
> selDir ='Empty'
> n='Empty'
> imgsList =
> 'C:/Users/matias/Desktop/resources/cars/pepe.jpg','C:/Users/matias/Desktop/resources/cars/ford.jpg'
>
> dirList ='ford.mb','mustang.mb'
> selDir = cmds.textScrollList('filesList', q=True, si=True)
> print "Something"
> print selDir
>
> for n in selDir:
> print n
>
> if n == "ford.mb":
> return imgsList[0]
> if n == "mustang.mb":
> return imgsList[1]
>
> def assetsList():
> dirList ='Cars','Trees','Furniture'
>
> selDir = cmds.textScrollList('dirs', q=True, si=True)
>
> cmds.textScrollList('filesList',fn='boldLabelFont',e=True,si=True,ams=True,ra=True,
> append=selDir)
>
> if selDir == "":
> print "Render Passes Please"
> else:
> for item in selDir:
> print item
>
> if item == "Cars":
> carModels()
> selDir==""
>
> if item == "Trees":
> treesModels()
> selDir==""
>
> if item == "Furniture":
> furnitureModels()
> selDir==""
>
> def carModels():
> root = 'C:/Users/matias/Desktop/resources/'
> cars = root +"/"+ 'cars'
>
> scenefiles = os.listdir(cars)
> for n in scenefiles:
> if n.rpartition(".")[2]=="mb" or n.rpartition(".")[2]=="ma":
>
> cmds.textScrollList("filesList",e=True,ra=False,append=n)
>
>
> def treesModels():
> root = 'C:/Users/matias/Desktop/resources/'
> trees = root +"/"+ 'trees'
> scenefiles = os.listdir(trees)
> for n in scenefiles:
> if n.rpartition(".")[2]=="mb":
>
> cmds.textScrollList("filesList",e=True,ra=False,append=n)
>
>
> def furnitureModels():
> root = 'C:/Users/matias/Desktop/resources/'
> furniture = root +"/"+ 'furniture'
> scenefiles = os.listdir(furniture)
> for n in scenefiles:
> if n.rpartition(".")[2]=="mb":
>
> cmds.textScrollList("filesList",e=True,ra=False,append=n)
> populate()
>
> On Sat, Jun 9, 2012 at 1:38 PM, Justin Israel <[email protected]> wrote:
> Did you mean: imageUi = cmds.image(image=pic()) ?
>
> I forget how well an image ui object updates but have you tried just editing
> the existing one?
>
> cmds.image(imageUi, e=True, image=pic())
>
> The image command doesnt accept a callable as a value. You have to edit it
> with a new image. If for some reason the ui object just refresh well when
> being edited, the 2nd option is to delete it and create a new one.
>
>
>
> On Jun 9, 2012, at 7:31 AM, Matias Volonte <[email protected]> wrote:
>
>> Hello everybody,
>>
>> I have a panel and in that panel I am displaying an image using
>> cmds.image(name=pic() ) python parameter. The problem is that I want that
>> image to update, reload or refresh according to what object I have
>> selected.I wrote a function that does that but apparently cmds.image() does
>> not accept it just ask for a straight image paht.
>>
>> if anyone can give me some kind of help will be appreciated, thanks.
>>
>> --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings:
>> http://groups.google.com/group/python_inside_maya/subscribe
>
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe