CINEVERSITY

  • Recent
  • Popular
  • Users
  • Groups
  • Login
Maxon Logo
  • Login
  • Search
  • Recent
  • Popular
  • Users
  • Groups

Xpresso-Python: how to access an object from the python script

Question & Answers
2
5
350
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O
    OPS last edited by OPS Jul 1, 2024, 6:01 PM Jul 1, 2024, 6:00 PM

    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!

    1 Reply Last reply Reply Quote
    • O
      OPS last edited by Jul 1, 2024, 6:08 PM

      Here's my C4D file:
      https://www.dropbox.com/scl/fi/mmyjml144miaysi9dsxni/XPressoTest.c4d?rlkey=67qbiypwtc68hgfebb8n3li7a&st=syo542kn&dl=0

      On the Xpresso tag of the Antihydrogen node, you will find the Python node that I'm referring to.

      1 Reply Last reply Reply Quote
      • Dr. Sassi
        Dr. Sassi last edited by Dr. Sassi Jul 1, 2024, 6:54 PM Jul 1, 2024, 6:46 PM

        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_____0

        The "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.c4d

        Screenshot 2024-07-01 at 11.42.44 AM.jpg

        All the best

        Dr. Sassi Sassmannshausen Ph.D.
        Senior Trainer, Maxon Master Trainer, L&D - Strategist
        Cinema 4D mentor since 2004, Member of VES, DCS.

        1 Reply Last reply Reply Quote
        • O
          OPS last edited by Jul 1, 2024, 7:44 PM

          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.

          1 Reply Last reply Reply Quote
          • Dr. Sassi
            Dr. Sassi last edited by Dr. Sassi Jul 2, 2024, 5:05 AM Jul 2, 2024, 5:03 AM

            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.

            CV4_2024_drs_24_XPos_11.c4d

            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.

            CV4_2024_drs_24_XPos_12.c4d

            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=flip

            All the best

            Dr. Sassi Sassmannshausen Ph.D.
            Senior Trainer, Maxon Master Trainer, L&D - Strategist
            Cinema 4D mentor since 2004, Member of VES, DCS.

            1 Reply Last reply Reply Quote
            • First post
              1/5
              Last post