Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I am trying to set an attribute on a pymxs-node based on the string name of an attribute.
It seems to work fine for simple attributes:
import pymxs rt = pymxs.runtime teapot = rt.teapot() attribute = "ishidden" setattr(teapot, attribute, True)
but when I need to set nested attributes ("controller.position.x") I run into problems.
Normally I would expect that I need to find the teapot.controller.position-object and then setattr on that:
import pymxs rt = pymxs.runtime teapot = rt.teapot() object = teapot attribute = "controller.position.x" attribute_parts = attribute.split(".") for a in attribute_parts[:-1]: object = getattr(object, a) print "posX: {0}".format(getattr(object, attribute_parts[-1])) # prints: posX: 0.0 setattr(object, attribute_parts[-1], 20) print "posX: {0}".format(getattr(object, attribute_parts[-1])) # prints: posX: 20.0
this all looks fine, but my object doesn't update in the viewport, and if i try to get the controller.position-object again, it hasn't changed:
object = teapot attribute = "controller.position.x" attribute_parts = attribute.split(".") for a in attribute_parts[:-1]: object = getattr(object, a) print "posX: {0}".format(getattr(object, attribute_parts[-1]))
# prints: posX: 0.0
any ideas on how to set that kind of attribute?
Solved! Go to Solution.