Python Object for attribute failed to deserialize

   2382   6   5
User Avatar
Member
15 posts
Joined: 2月 2016
Offline
Hi there,

I've got a PyObject attribute on a work item, which is a list of several instances of my own python object. I'd like to iterate over each of these objects in maya (they each hold some data about stuff to do, and I have some code running on the maya side to deal with them).

It works fine in Houdini if I inspect some of the attributes of the objects in the list with a Python Script TOP and have it print out to the terminal. But as soon as it hits the maya command chain portion, the log says "Python object for attribute 'components' failed to deserialize". ('components' is the work item attribute name). Is there anything I need to include in my Python objects to get them to deserialize properly?

Please excuse me if I haven't nailed all the terminology, I'm still getting started with PDG.

I searched the forums and couldn't really find a solution. Any insight would be greatly appreciated. Thanks!
User Avatar
Member
72 posts
Joined:
Offline
There's a video, I think when PDG was released that goes into Maya/PDG. If I recall correctly that as soon as the server is running all python code is running in the PyMel env of Maya. So any special data you cary into maya will not just work out of the box I think. I'd say you need to convert the PyObject to something more basic before pushing it into maya server, like a basic dict or list.

Again never had to do it, so I might be way off.

edit : https://www.youtube.com/watch?v=t0bhiCoDR8M [www.youtube.com]
that's the video I had in mind, lot's of info on maya/pdg
Edited by Johan Boekhoven - 2020年7月24日 07:35:01
User Avatar
Member
603 posts
Joined: 9月 2016
Offline
By default the PyObject attributes are serialized using `repr()` and deserialized using `eval()`. This means only simple objects that have compatible __repr__ output will automatically work.
User Avatar
Member
15 posts
Joined: 2月 2016
Offline
Thank you both for the quick replies!

Johan Boekhoven
I'd say you need to convert the PyObject to something more basic before pushing it into maya server, like a basic dict or list

Yeah, I think you might be right.


chrisgreb
This means only simple objects that have compatible __repr__ output will automatically work
Okay, that's sort of what I was thinking might be the case. I realized last night that I can actually do most of everything I need to do using the stock task operators (which is pretty sweet), so I think I will go that route instead.

Thanks again for the help!
User Avatar
Member
10 posts
Joined: 10月 2015
Offline
Chris - you mention this is the default behaviour, does that mean as users we are able to adjust this workflow? Perhaps using Pickle or some other similar serialisation module? I can imagine that would allow for even more flexibility when using command servers or PDGD.
Matt Traynar

Software Developer @ MPC
User Avatar
Member
603 posts
Joined: 9月 2016
Offline
Indeed there is a hook to change the serialization:

https://www.sidefx.com/docs/houdini/tops/pdg/TypeRegistry.html#setPySerializationModule [www.sidefx.com]
User Avatar
Member
10 posts
Joined: 10月 2015
Offline
Great news! Thanks.
Matt Traynar

Software Developer @ MPC
  • Quick Links