Obtaining Properties from other objects with the Python Effector


#1

I just started learning how to use the Python effector, and I’m wondering if it’s possible for it to access other objects in the code the way Xpresso can. For example, I currently have the following setup:

As you can see, a value that I’m using in the Python effector depends on a value from a completely separate cloner that it is NOT affecting.

My question is this; is it possible to, from within the Python code, obtain those same values? Can a Python Effector object which is effecting object A access properties from object B? If so, how? Can you give an example?


#2

You simply need to pass the object in question into the Python node as a link.
Like so:
image

Then it’s just a matter of reading whatever you want from that object, e.g. like so:

import c4d

def main():
    global Cube_Size
    Cube_Size = An_Object.GetAbsPos().__abs__()
    # You can read(!) any parameter here, e.g. An_Object[c4d.PRIM_SPHERE_RAD]

And here’s the example scene, containing the above:
test_xpresso_param_access.c4d (222.4 KB)

One word of warning though:
You should not modify an object (including the host object of the Xpresso tag) from within the Python node. Instead pass your results to output ports and link these to the parameters of respective object nodes. I know, modifying objects from within the Python node may seem to work. But it’s a risky game, especially for other objects. Rather use the object node, internally it’s made in a way such changes happen safely and as expected.

Cheers


#3

this is really very useful and knowledgable blog!!


#4

very interesting and useful information i just found here keep it up@!!


#5

Thanks, but I’m not sure how to pass in the object as a paramter; I’m using a Python effector in my xpresso while you’re using a Python node. Is it possible to pass objects to a Python Effector? Right clicking on the blue section does not present the same options that a regular Python node presents.