On Wed, May 15, 2019, 7:24 AM Alon Zaslavsky <al...@tippett.com> wrote:

> I'm not sure what your end goal is. But if it's just to get whats in the
> dictionary, use the iteritems dictionary method.
>
> dict = {'A': 'sphere1', 'B': 'sphere2'}
> for key, val in dict.iteritems():
>     print key, val
>
> I tested it with the value being a pymel class object and it works too.
>

The issue isn't actually the container for which the data is stored or
read. It's the serialization of the PyMel node and then reading it back in
later. The constructor of the PyMel node expects the object in the scene to
exist otherwise you get an exception. So the suggestion was to serialize to
a format that wouldn't automatically run the PyMel node constructors so
that each one can be manually converted.


> On Thu, May 2, 2019 at 2:24 AM Zhen Huang <qeejiw...@gmail.com> wrote:
>
>> Hi ,
>>
>> I have a question about python build-in function 'eval ' , please check
>> out the example code below :
>>
>> ## create a polySphere , default name : 'pSphere1'
>>
>> import pymel.core as pm
>> from pymel.core import nt
>>
>> # initialize a pymel transform node
>> pymelShpere = pm.PyNode('pSphere1')
>> # put it to a dict
>> testDict = {0:pymelShpere}
>> # convert it to str which can be stored as string in file basic data
>> strMark = str(testDict)
>>
>> # now read it back , if scene has the pShere1 , it will work perfectly
>> newDict = eval(strMark)
>>
>> # now delete the pShpere1 , and try to convert data to dict , failed
>> because the pymel nt will try to initialize the string 'pShere1' to pymel
>> node
>> newDict =eval(strMark)
>>
>>
>> My question : if I have lots of nodes store in a string data which
>> convert from dict , is there a way to just make it out , just ignore error
>> part or if node not exists it just convert from nt to string name ?
>> if pSphere2 not exist then return
>>
>> {0:nt.Transform('pSphere1'), 1:'pSphere2' }
>>
>>
>>
>> Any idea is very much welcome , big thanks !!!
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/3f87dcf5-3171-47e7-bec5-a56d550513d1%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/3f87dcf5-3171-47e7-bec5-a56d550513d1%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Alon Zaslavsky
> Puppet TD
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAKjYKQkJQB%3D2e3JX0jtcjoQN0xcy41ELn0%2BVnYnhEvWYUi0OXg%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAKjYKQkJQB%3D2e3JX0jtcjoQN0xcy41ELn0%2BVnYnhEvWYUi0OXg%40mail.gmail.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA065335qWQiOLEne-iHG-VoeAqreRefR79bZJ3gjddJSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to