Change Global Matrix fails

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 08:24, xxxxxxxx wrote:

Hy there,

I just have a strange little problem. I already wrote a complete car-simulator in python, but the following really simple example just does not work.

What do I miss?

This code is in a Xpresso Node on a plane (can be any object), o is the Object-Link:

import c4d

def main() :
  global o

m = o.GetMg()
 
  print m.off.y
  m.off.y = m.off.y + 100
  print m.off.y
 
  o.SetMg(m) 
  print m

The two print-statements will output the same value for y ... and the position of the object will not change.

... is there a way to attach an example-scene ?

Thanx,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 09:03, xxxxxxxx wrote:

... creating my own matrix does not work either ??

import c4d

def main() :
  global o

m = o.GetMg()
  mn = c4d.Matrix(m.off,m.v1,m.v2,m.v3)

print mn.off.y
  mn.off.y = 500
  print mn.off.y
 
  o.SetMg(mn) 
  print mn

The same output, y stays the same ...

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 09:38, xxxxxxxx wrote:

In your example mn.off returns a new vector object where you change y. So the value is not assigned to the component of the internal vector of the Matrix.

v=mn.off
v.y=500
mn.off=v

Hope this helps.

Cheers, Sebastian

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 09:54, xxxxxxxx wrote:

Hmm, so

mn.off is a method call ? I thought mn.off is just a reference to the c4d.Vector ?

Thank you,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 10:12, xxxxxxxx wrote:

Yes, it referres to the off component of a matrix.
But getting an attribute of an instance invokes the instances __getattr ibute __ method, so it returns a value.

@Sebastian:
Why is the returned Vector not the original instance ? If so, that would do it all:

mn.off.y = 20.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 10:22, xxxxxxxx wrote:

How can I know, that matrix.off will become a method call?

I can't see anything in the Matrix-API telling me that ?

So, for now, each time when I access a member, I will need to check if it returns me a copy or not?

Cheers,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 12:52, xxxxxxxx wrote:

No. Sorry, I didn't want to confuse you. 😕

In Pyhton, most classes support a methode called "__getattribute__" which is invoked when you want to get an attribute. The returnvalue of this method is what you recieve from the attribute-acess.

The lower text was jsut for Sebastian. 😉

No, you don't have to look it up. It's standart in Cinema 4D, and many other programs. I'm sure there is a sense, but I couldn't it figure out, yet.

If the original isntance would have been returned, and not a copy, changing the vectors value would take affect in the matrix, too.

That's how it's working:

import c4d  
  
m = c4d.Matrix(*[c4d.Vector(0) for i in xrange(4)])  
v = m.off  
v.x = 100  
print m.off.x # 0  
  
m.off.x = 100  
print m.off.x # 0  
  
m.off = v  
print m.off.x # 100, what we wanted :)

More on Special Methods here.

Cheers, Niklas

PS: Yes it's wrong what i wrote in the previous post, not "getattr", instead "getattribute"

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 13:36, xxxxxxxx wrote:

You didn't confuse me, it was the correct explanation 😉

But assume the Vector class wouldn't consist of atomic values, instead of references to a simple value-container class.

Now, if I call v.x = 100 I again can't be sure, if I just set the value to a copy (of the simpe value-continer) or the actual container value of v (just if the API would state so). Who tells me, when there is a hidden call ??

This seems a pretty strange concept to me, as I can't be sure that a reference to an attribute contains (or, returns) a copy or not ...

Cheers,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 14:02, xxxxxxxx wrote:

You can be sure. It is as it is. 😂

A matrix object does return a vector by calling i.e. m.off . But modifing this vector does not modify the original vector in the matrix.

A vector object does return an integer by calling i.e. v.x . But you can't modify this integer.
By setting a value to the vector, you set the value to the vector, not to a copy.

Omg, weird thing :S

btw, v.x = 100 invokes "v.__setattr__(100)", not "v.__getattribute__("x") = 100"

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 14:45, xxxxxxxx wrote:

btw, v.x = 100 invokes "v.__setattr__(100)", not "v.__getattribute__("x") = 100"

Ok. Now its really clear 😉

Until now, I just got lucky, as I always created a vector first and then I set it on the matrix. This seems to be the first time, I tried to access a vector-component directly in this manner ...

Thank you,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 23:48, xxxxxxxx wrote:

It depends on the type and the level of access. If you call Matrix().off a copy (not the reference to the off vector) is returned. That yourmatrix.off.x=30 does not work is unfortunately a technical limitation. I will make a note for the docs.