Results 1 to 7 of 7

Thread: text scroll list issue

  1. #1
    integer
    Join Date
    Dec 2008
    Location
    Fairfield, CA
    Posts
    35

    Default text scroll list issue



    Hello,
    I am a student in college and i have been studying scripting, mostly python. I was working on a tool set just for practice and i added a text scroll list to it and i wanted it to query all the keyable attributes on a selected item and put them on the list. I got that working but then when i wanted to use the list to lock and hide selected attributes i reaized that translateX means nothing. So i was trying to set it so when it builds the list it would take the name of the selected object and put objName.attr for each entry. That is where i ran into a problem. I am running a str variable to pull the selected object and then running a for loop to go through and add the attributes. But when i do that here is the error i recieve
    Code:
    # TypeError: can only concatenate list (not "str") to list #
    And here is my code i am running.
    Code:
    def add():
    	#Add to Attr List
    	cmds.textScrollList("Attr", e=1, ra=1)
    	selected = cmds.ls(sl=1)
    	for sel in selected:
    		attr = cmds.listAttr(sel, k=1)
    		final = str(selected + "." + attr)
    		cmds.textScrollList("Attr", e=1, append= final)
    EDIT: Also it is ment to run one item at a time, so maybe the loop is not needed, but from tests that isnt the cause of the problem.

  2. #2
    Technical Director
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    130

    Default

    You are trying to concatenate two lists (selected and attr) together deliminated by a string which won't work.
    You could set up two loops to do what you're after:
    Code:
    # Define final list
    finalList = []
    
    # Loop through all the selected objects
    for sel in selected:
    	# Get keyable attributes list for this object
    	attrList = cmds.listAttr(sel, k=1)
    	
    	# Loop through each attribute
    	for attr in attrList:
    		# Add object name to attribute
    		attrName = sel + "." + attr
    		
    		# Add attribute to final list
    		finalList.append (attrName)
    
    # This command takes a list we've generated above
    cmds.textScrollList("Attr", e=1, append= finalList)
    You can also use list comprehension to make the code more neat or so some would say:

    Code:
    # Define final list
    finalList = []
    
    # Loop through all the selected objects
    for sel in selected:
    	# Get keyable attributes list for this object
    	attrList = cmds.listAttr(sel, k=1)
    	
    	# Compute the attribute list to add the object name to each item
    	newAttrList = [sel + "." + x for x in attrList]
    	
    	# Add attributes to the final list
    	finalList.extend (newAttrList)
    
    # This command takes a list we've generated above
    cmds.textScrollList("Attr", e=1, append= finalList)
    Hope this help!
    Last edited by ShadowM8; 12-28-2008 at 07:07 AM.

  3. #3
    integer
    Join Date
    Dec 2008
    Location
    Fairfield, CA
    Posts
    35

    Default

    Thank you very much, worked like a charm.
    Instead of starting a new thread ill just post this here. I was messing around with frameLayouts and ran into a problem. I coded a little procedure that when the window is collapsed it shrinks the window and when it is expanded it grows the window. I have a small issue where it is not putting the correct values. Here are the two procedures
    Code:
    def collapse():
    	inWindowHeight = cmds.window(win, q=1, h=1)
    	frame1 = cmds.frameLayout("rigTools", q=1, cl=1)
    	frame1H = 240
    	frame2 = cmds.frameLayout("controls", q=1, cl=1)
    	frame2H = 177
    	frame3 = cmds.frameLayout("constraint", q=1, cl=1)
    	frame3H = 154
    	frame4 = cmds.frameLayout("cleanUp", q=1, cl=1)
    	frame4H = 163
    	if(frame1==1):
    		sub1 = (inWindowHeight - frame1H)
    		cmds.window(win, e=1, h=sub1)
    		print(sub1)
    	if(frame2==1):
    		sub2 = (inWindowHeight - frame2H)
    		cmds.window(win, e=1, h=sub2)
    		print(sub2)
    	if(frame3==1):
    		sub3 = (inWindowHeight - frame3H)
    		cmds.window(win, e=1, h=sub3)
    		print(sub3)
    	if(frame4==1):
    		sub4 = (inWindowHeight - frame4H)
    		cmds.window(win, e=1, h=sub4)
    		print(sub4)
    
    def expand():
    	inWindowHeight = cmds.window(win, q=1, h=1)
    	frame1 = cmds.frameLayout("rigTools", q=1, cl=1)
    	frame1H = 240
    	frame2 = cmds.frameLayout("controls", q=1, cl=1)
    	frame2H = 177
    	frame3 = cmds.frameLayout("constraint", q=1, cl=1)
    	frame3H = 154
    	frame4 = cmds.frameLayout("cleanUp", q=1, cl=1)
    	frame4H = 163
    	if(frame1==0):
    		add1 = (inWindowHeight + frame1H)
    		cmds.window(win, e=1, h=add1)
    	if(frame2==0):
    		add2 = (inWindowHeight + frame2H)
    		cmds.window(win, e=1, h=add2)
    	if(frame3==0):
    		add3 = (inWindowHeight + frame3H)
    		cmds.window(win, e=1, h=add3)
    	if(frame4==0):
    		add4 = (inWindowHeight + frame4H)
    		cmds.window(win, e=1, h=add4)
    Now, when i collapse all of them except the 4th frame, they give odd values. Some of them print the value it should be putting in and other times it puts in some random value that doesnt even subract out right.

  4. #4
    Technical Director
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    130

    Default

    Not sure exactly what is going on but from the first glance if you have more than a single frame closed/opened you will have issues because you are not updating your inWindowHeight value with each change.

  5. #5
    integer
    Join Date
    Dec 2008
    Location
    Fairfield, CA
    Posts
    35

    Default

    Wouldn't it be queried every time the procedure is called? Which would be every time a frame is collapsed or expanded. At least that is how I thought procedures worked. But once I get working today I will post what exact numbers I am getting on collapses and expands.

  6. #6
    Technical Director
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    130

    Default

    It does, what I ment is if frame1 is collapsed you set a new window hieght so when you get to frame2 the inWindowHeight you queried above is outdated. So maybe thats why the values you get are not what you expect?

  7. #7
    integer
    Join Date
    Dec 2008
    Location
    Fairfield, CA
    Posts
    35

    Default

    Hmm, maybe, When i run the script and collapse for frame when when it expands, it expands properly, but when it collapses it gives a return of 190. But ill reload the script and re-run it and expand and collapse just that frame and it gives a return value of 190. When it is expanded though it gives a window height of 353, so if 240 is subtracted from that it should give back 113 but it gives 190, and i dont know where it could be getting that........ok, wow, as im typing this i realized it is taking the wrong values and subtracting them. What its doing is when it collapse it is doing is subtracting by the fourth frames value. So i just need to re-write it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •