Xpresso-Python: how to access an object from the python script
-
Hello,
an Xpresso python newbie here.How can I set a new spline object to the 'Align to Spline' tag inside the python node in Xpresso?
I am using Xpresso to calculate the distance between two objects and inside the Python node, I check if the distance is less than a certain length, I set a different spline object to the 'Align to Spline' tag of an object. To achieve this, I've tried dragging the new spline object into the python script. I've also tried setting it as a user data of the python node and used it inside the python script, but neither way worked.
Overall, I don't know how to access the objects in the Object Manager from the Python node. If someone can shed a light on this, I'd most appreciate it!
Thank you in advance! -
Here's my C4D file:
https://www.dropbox.com/scl/fi/mmyjml144miaysi9dsxni/XPressoTest.c4d?rlkey=67qbiypwtc68hgfebb8n3li7a&st=syo542kn&dl=0On the Xpresso tag of the Antihydrogen node, you will find the Python node that I'm referring to.
-
Hi OPS,
Thanks for the file.
The Spline path is a link, so it would place an object via a link into the Node. The Python Node has very little power to create such a Spline. It is more about doing math with it, or creating lists, etc.
For anything Python and code, please check the Developer Forum, or as it was called, the Developer Café.
https://developers.maxon.net/forum/
By default, this forum here is code-free, as it would be impossible for me to control every Python script every day if it was not changed and contained all the sudden malware.
.
This is pretty much how I read it here in the manual:
https://help.maxon.net/c4d/2024/en-us/Default.htm#html/GVPYTHON.html?TocPath=XPresso%257CXPresso%2520Nodes%257CScript%2520(Group)%257CPython%2520Operator%257C_____0The "Positron Spline Align Tag" in your file has a Position output. Perhaps that is a first step toward your solution.
With this assumption, I have set up something that hopefully helps you get closer to your target.
CV4_2024_drs_24_XPos_01.c4dAll the best
-
Thanks Dr. Sassi!
I didn't think that the Python Node in Xpresso is limited in that way, but good to know. I'll think of a work around using other Xpresso nodes.
I wanted to use the Python node because I wanted to make the spline object change only once in the scene session when certain conditions are met.For example, in your file, let's say that the 'Extrude Instance's Reference Object is set to Text Spline.0 'manually' at frame 0. How can I set it to Text Spline 2 if and only if when the distance from the range mapper gives 2, but leave it as Text Spline.0 otherwise? AND to make this change only once and not keep changing back and forth between Text Spline 0 and Text Spline 2 as the distance oscillates? I thought of using a global variable in python to keep track of the change (like a boolean isChanged) and execute the change only once. But may be I am totally off in my way to achieve the target.
Let me know if you have any helpful hints.
-
Hi OPS,
Please have a look here. This is the simple version—a demo of the process. Press play and move the Sphere. A second Xpresso Tag is created to reset the Sphere on Frame zero.
This file below has the Spline setup. I use the MoSpline set to Spline to take a source file in and produce a Destination Spline. This destination Spline can be adjusted inside the MoSpline and, as it is a Spline, used as any other Spline in Cinema 4D. However, it is determined by the MoSpline.
The core idea is to use the FlipFlop Node.
https://help.maxon.net/c4d/en-us/?_gl=11fw48s_gcl_au*MTQ5NzQ3MDQ5MS4xNzEyMzQzNjY2#html/GVTRIGGER.html?Highlight=flipAll the best