Hi Flavio,
no, worries, as long as at least a little bit of scripting is involved, this forum is the correct place. Even if it's about translating Xpresso to Python for learning purposes.
@fwilleke80: you might be able to call those objects' NodeData's GetHandle() function
Frank's suggestion won't work in Python (while certainly being an optin in C++), as there are no means to get the NodeData belonging to a deformer's BaseObject.
I assume, the code you show in the screen recording is in the Python tag on the "Finger" Null object?
There are a few things to consider:
- You simply wrote your code into a function
gethandle()
without calling this function. You can not expect C4D to call this arbitrary function.
- A tag (or expression) must only modify its host object (please leave aside Xpresso tags, e.g. the object nodes there contain special code to make an exception from this rule). So the Python tag should be placed on the Bend deformer.
- The "Control" Null object can move freely in 3D space, while the handle can not. So, you'd either need to also constrain the Null object in some way or live with the fact that the Null can move away from the handle in Y axis.
With all this said, a very simply version of a Python tag's code could look like so (ignoring the fact the Null can be moved away in Y axis):
import c4d, math
def main():
# Somehow get the control object
# In this example it's simply the first object,
# but it could also come from e.g. a user data parameter (type Link)
opControl = doc.GetFirstObject()
# Get the host object of the Python tag (the Bend deformer)
opBend = op.GetObject()
# Get the position of the Bend deformer and the controlling Null object
mgBend = opBend.GetMg()
offBend = mgBend.off
mgControl = opControl.GetMg()
offControl = mgControl.off
# diff is basically the position of the controlling Null in Bend deformer's local space
diff = offControl - offBend
diff.y = 0.0 # ignoring any differences in y direction in this example
# calculate the strength and angle parameters
strength = diff.GetLength() / (opBend[c4d.DEFORMOBJECT_SIZE].y * 0.5)
angle = c4d.utils.GetAngle(diff, c4d.Vector(1.0, 0.0, 0.0))
if diff.z < 0.0:
angle = 2.0 * math.pi - angle
# set the parameters
opBend[c4d.DEFORMOBJECT_STRENGTH] = strength
opBend[c4d.DEFORMOBJECT_ANGLE] = angle
linking_something_to_a_handle.c4d
Cheers,
Andreas