dict values are not updating

26 views
Skip to first unread message

yann19

unread,
Jul 19, 2016, 1:45:21 PM7/19/16
to Python Programming for Autodesk Maya
Pardon me if this is a beginner question..

# optionVar name: (type, default value, corresponding class attribute)
# The class methods only check for 'iv' and 'fv' types while looping thru
spOptionVars
= {"spTransformRotate": ("iv", 1, "transform_rotate"),
               
"spPaintDistance": ("fv", 10, "paint_distance")}
                   
                   
class spToolOption (object):
   
def __init__ (self):
       
self.transform_rotate = True
       
self.paintDist = 10
       
...
       
...


   
def commitVars(self):
       
"""
        Updates the change in value of the variables if any
        """

       
for name, info in spOptionVars.iteritems():    
            type
, value, varname = info
           
if (type == 'iv'):
                mc
.optionVar(iv=(name, int(self.__dict__[varname])))
           
elif (type == 'fv'):
                mc
.optionVar(fv=(name, self.__dict__[varname]))
               
               
print ">>> 1. ", name
               
print ">>> 2. ", self.__dict__[varname]
               
print ">>> 3. ", varname


While I am using a text field which triggers this 'paint_distance', as soon as there is a change in value in that text field, it will updates the values in the dict accordingly.

However as its initial variable name is 'paintDistance', I changed it to 'paint_distance' and this updating is no longer working.

I did a double/triple check to make sure that all 'paintDistance' names are changed to 'paint_distance' and only in the above code, only 'spPaintDistance' exists in that
code portion above.

Also. any changes in the naming such as 'paintDist' etc will simply not work.

# Before any value change
>>> 1.  spPaintDistance
>>> 2.  10
>>> 3.  paint_distance

Suppose I am changing the value from 10 to 5, it still reflects as 10.
# After any value change
>>> 1.  spPaintDistance
>>> 2.  10
>>> 3.  paint_distance

It will only change to value of 5 unless I remove the underscores and change it to 'paintDistance' which is its default name that was given in the first place.

Suppose I am changing the value from 10 to 5, it still reflects as 10.
# After any value change
>>> 1.  spPaintDistance
>>> 2.  5
>>> 3.  paintDistance


Anyone can enlighten me on this part?


Cesar Saez

unread,
Jul 20, 2016, 6:56:31 AM7/20/16
to python_in...@googlegroups.com
Is this happening within maya? have you tried restarting Maya to clear the global state?
You know, maya share the same interpreter during the whole session and variables declared in the main namespace/scope will be there for the entire session.

Cheers!

Marcus Ottosson

unread,
Jul 20, 2016, 7:26:37 AM7/20/16
to python_in...@googlegroups.com
Where in your code are you expecting spOptionVars to be updated?

--
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/CAPamJi_hiWmfWBbGjE73e0nZc%2B6Sp%3DuGQ%3DcnLweGk%2BqPtpwuQQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

yann19

unread,
Jul 20, 2016, 12:37:58 PM7/20/16
to Python Programming for Autodesk Maya

Is this happening within maya? have you tried restarting Maya to clear the global state?

How do you clear the global state? I did restart my maya a few times and it is giving me the same problem..
And yes, I think it is happening within Maya since my code is executed within there.
 
You know, maya share the same interpreter during the whole session and variables declared in the main namespace/scope will be there for the entire session.

I did try to change my file name, variable names etc but still the same thing is happening which stumps me

yann19

unread,
Jul 20, 2016, 12:38:59 PM7/20/16
to Python Programming for Autodesk Maya
Where in your code are you expecting spOptionVars to be updated?
It should be updated in the commitVars function that I have stated in my first post where as soon as a change in value in this text field is detected 
Reply all
Reply to author
Forward
0 new messages