PDA

View Full Version : problem with replacing info in textscrolllist


boulba
01-15-2011, 11:13 AM
im using two textscrolllist to show the lights in the scene. One with all the lights and one the lights gets append to when i change the intensity.

The problem is that if I change the intensity of a light twice the old information remains and the light appears twice in the list instead of being replaced with the new information.

I have tried if loops, in cmds, list with brackets and temporary variables but the closed ive got to a solution is that the light do gets replaced but on top of that the whole list gets wiped but I want to keep the other lights that I only change the intensity on once.

Would really appreciate some help!



Here is the code im running.

def lightvalue():
selLights=cmds.textScrollList('changeintensity',q=1,si=True)
value=cmds.floatField("relvalue",q=1,v=1)
currentLight=cmds.textScrollList('changedintensity',q=1,ai=True)



for sel in selLights:


print "steg1"
currentvalue=cmds.getAttr(sel+'.intensity')
newvalue=currentvalue+value
cmds.textScrollList('changedintensity',e=1,a=sel+" "+str(newvalue))
cmds.setAttr(sel+'.intensity',newvalue)
print currentLight
print sel

mduvekot
01-15-2011, 01:12 PM
store the items you want to remove in a dict and use the name of the item in your first textScrollList as the key

for sel in selLights:
currentvalue = cmds.getAttr(sel+'.intensity')
newvalue = currentvalue + .1
v = sel+" "+str(newvalue)

# remove existing items
for i in d[sel]:
cmds.textScrollList(tsl2, edit=True, removeItem=i)
#add new item
if sel in d.keys():
d[sel].append(v)
else:
d[sel] = [v]

cmds.textScrollList(tsl2,edit=True,append=v)
cmds.setAttr(sel+'.intensity',newvalue)

boulba
01-16-2011, 03:25 PM
OK. I came a bit on the way. After implementing your suggestion I ran into an error that said that the sel variable was not an int. I think I solved that problem, however my current issue is the error: ValueError: invalid literal for int() with base 10: 'directionalLightShape3' #

I have searched on the web for it but its somewhat unlcear what is actually means and therefore it very heard to fix the code when I do not know what the problem is.

Do you know?


def lightvalue():
selLights=cmds.textScrollList('changeintensity',q=1,si=True)
value=cmds.intField("relvalue",q=1,v=1)
currentLight=cmds.textScrollList('changedintensity',q=1,ai=True)

for sel in selLights:
currentvalue=cmds.getAttr(sel+'.intensity')
newvalue=currentvalue+value
light=sel+" "+str(newvalue)


#remove item
lnr= int(sel)
for l in selLights[lnr]:

cmds.textScrollList('changedintensity',e=1,ri=l)
#add
if sel in selLights.keys():
selLights[lnr].append(light)
else:
selLights[lnr]=[light]

cmds.textScrollList('changedintensity',e=1,a=light)
cmds.setAttr(sel+'.intensity',newvalue)

mduvekot
01-16-2011, 07:00 PM
.. you're using a list [] in stead of a dictionary {}?

boulba
01-22-2011, 04:16 PM
Ive been trying to use the dictionary, but I cannot see how to make a dictionary dynamic. I understand how to "predefine" the content in the dict, but I cannot quite see how to create a dictionary and then append the content after when I use the script. I got the error: type' object is unsubscriptable about the sel variable which apparently means that sel is a Nonetype variable, but the sel varible contains a light which it should. Im just very confused here. Do you have any suggestions?




def lightvalue():
selLights=cmds.textScrollList('changeintensity',q=1,si=True)
value=cmds.intField("relvalue",q=1,v=1)
currentLight=cmds.textScrollList('changedintensity',q=1,ai=True)

for sel in selLights:
print sel
currentvalue=cmds.getAttr(sel+'.intensity')
newvalue=currentvalue+value
light=sel+" "+str(newvalue)


#remove item
#dict()

for l in dict[sel]:

cmds.textScrollList('changedintensity',e=1,ri=l)
#add
if sel in selLights.keys():
selLights[sel].append[light]
else:
selLights[sel]=[light]

cmds.textScrollList('changedintensity',e=1,a=light)
cmds.setAttr(sel+'.intensity',newvalue)

mduvekot
01-22-2011, 07:21 PM
I suppose you want something like this:

class lightUI():
def createUI(self):
from maya import cmds as cmds
self.win =cmds.window(t='light intensities')
cmds.columnLayout(adj=True)
cmds.textScrollList('changeIntensity', ams=True)
cmds.textScrollList('changedIntensity')
cmds.rowLayout( numberOfColumns=2,
columnWidth2=(150, 100),
adjustableColumn=2,
columnAlign=(1, 'right'),
columnAttach=[(1, 'both', 0), (2, 'both', 0)] )
cmds.floatField('relvalue')
cmds.button(l='update', c=self.btnCB)
cmds.showWindow(self.win)
for light in cmds.ls(lights=True):
cmds.textScrollList('changeIntensity', edit=True, append=light)

def btnCB(self, *args):
for sel in cmds.textScrollList('changeIntensity', q=True, si=True):
currentvalue = cmds.getAttr(sel+'.intensity')
newvalue = currentvalue + cmds.floatField("relvalue", q=1, v=1)
v = sel + " " + str(newvalue)
try:
for i in self.d[sel]:
cmds.textScrollList('changedIntensity',
edit=True, removeItem=i)
except KeyError:
pass
if sel in self.d.keys():
self.d[sel].append(v)
else:
self.d[sel] = [v]
cmds.textScrollList('changedIntensity',
edit=True,append=v)
cmds.setAttr(sel+'.intensity',newvalue)

def __init__(self):
self.d = {}
self.createUI();

l = lightUI()

CGTalk Moderation
01-22-2011, 07:21 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.