How to use function updateAttrs

Asked by MikeZhao

There are many updateAttrs function in different classes, According to my knowledge, this function is used to change attributes of classes with a dictionary. But what's the parameter that I should give?

For instance, I'd like to update yade.O.bodies[10000].state.pos to [0,0,0], I write a code like that:
yade.O.bodies[10000].state.updateAttrs({yade.O.bodies[10000].state.pos:[0,0,0]})

and the result is:
TypeError: No registered converter was able to produce a C++ rvalue of type std::string from this Python object of type Vector3

How should I modify it?

Hope to get some help,

thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hi Mike,

updateAttrs is used mainly in serialization (saving/loading) of objects. In
your case, you can directly use

O.bodies[10000].state.pos = (0,0,0)

if you want to use updateAttrs, is accepts dictionary, whose keys are
srting names of attributes. So it could be

O.bodies[10000].state.updateAttrs({"pos":(0,0,0)})

However, it does not work. Sometimes the variables (like pos) are
internally treated in different way, e.g. pos is one part od Se3 instance,
containing position and orientation, so setting position with updateAttrs
would look like:

s = O.bodies[10000].state
s.updateAttrs({"se3":((0,0,0),s.ori)}) # (0,0,0) is new position, one part
of se3, the other part being orientation

As a conclusion, I would suggest to try to avoid using updateAttrs if
possible :-)

cheers
Jan

2015-06-06 15:46 GMT+02:00 MikeZhao <email address hidden>:

> New question #267838 on Yade:
> https://answers.launchpad.net/yade/+question/267838
>
> There are many updateAttrs function in different classes, According to my
> knowledge, this function is used to change attributes of classes with a
> dictionary. But what's the parameter that I should give?
>
> For instance, I'd like to update yade.O.bodies[10000].state.pos to
> [0,0,0], I write a code like that:
>
> yade.O.bodies[10000].state.updateAttrs({yade.O.bodies[10000].state.pos:[0,0,0]})
>
> and the result is:
> TypeError: No registered converter was able to produce a C++ rvalue of
> type std::string from this Python object of type Vector3
>
> How should I modify it?
>
> Hope to get some help,
>
> thanks.
>
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Can you help with this problem?

Provide an answer of your own, or ask MikeZhao for more information if necessary.

To post a message you must log in.