Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Sending user data from one node/tag to another

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 1.2k Views
    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.
    • H Offline
      Helper
      last edited by

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

      On 19/04/2011 at 02:17, xxxxxxxx wrote:

      I'm new to Python for C4D. I like to bumble around and use Google when learning something new like this, but I'm running into roadblocks that tell me I'm misunderstanding something and/or looking in the wrong place for answers.

      What I want to do is have a null with custom user data, like a y position slider. I want to have a C4D Python tag that I can drop on a separate object that will find the value of that y position slider. Two separate objects… in other words,  a Python tag reading a value from another node.

      In Maya it would be a simple expression like this:

      nurbsSphere1.translateY = control.customYControl

      I'm having trouble having a Python tag look outside of its bubble to read a variable from another node or py-tag.

      Is the problem just that I don't know how to properly identify the null and its user data for Python to find? Or do I need to put another Python tag on the control null as well and have it create a global variable that can be read by other Python tags? I think the global variable stuff I've tried is only "global" within the tag, not the whole document.

      In the end there are going to be hundreds of objects with many different Python tags all getting variables the single null control node. What is the efficient way to handle this?

      If you can help with a pointer in the right direction I would really appreciate it, especially if you can give a sample of the syntax. I'm not having any luck with generic Python tuts on the web, all my trouble seems to be coming from how C4D and Python relate to each other, not Python specifically.

      I've already got the SDK docs and have seen the Cineversity videos, and I know the trick where you drag a parameter into the py console to get its py-name. It don't work.

      Thanks --

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 19/04/2011 at 06:06, xxxxxxxx wrote:

        Hey Alexwarner,

        Hello Alex, please take a look at this:

        import c4d

        def main() :
         controller = doc.SearchObject("Main-Controller") // Search for the null-object
         if controller is None:
          return
         
         for id, bc in controller.GetUserDataContainer() :  // GetUserData and search for the correct one
          if bc.GetString(c4d.DESC_NAME) == "Data1":
        myid = id
         
         controller[myid] = 0.1 // Set the value

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 19/04/2011 at 13:00, xxxxxxxx wrote:

          Thanks so much for your help! This script works great with a tiny tweak -- as written the script changes the value in the null controller, and I need it to get  a value in the null controller to be used in an expression that affects the object that has the py-tag on it. Super easy change, here it is:

          import c4d

          obj = op.GetObject()

          def main() :
           controller = doc.SearchObject("Main-Controller") // Search for the null-object
           if controller is None:
            return
           
           for id, bc in controller.GetUserDataContainer() :  // GetUserData and search for the correct one
            if bc.GetString(c4d.DESC_NAME) == "Data1":
          myid = id
           
           t = doc.GetTime().Get() // Set the time variable

          obj.SetAbsPos(c4d.Vector(0,t*controller[myid],0)) // Time times controller value equals y pos

          One thing I want to continue to investigate is why I can't tell the script the name of the node and its user data channel specifically, or create a truly global variable (all py-tags can read it once it's defined). It seems like if i have a hundred of these py-tags all doing search operations at every frame refresh times the number of channels it is reading, things get inefficient -- where somehow a global variable could be defined once and available to all py-tags.

          Thanks again!

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 19/04/2011 at 13:38, xxxxxxxx wrote:

            If you don't wan't to search for a specific Object in the scene by name, why not adding a userdata on the Tag containg the 'Main-Controller' Object ?

            Making a global variable available for all Tags is not
            possible and will never be.
            To exchange data between your tags, you have to use userdata.
            But, why using multiple tags and exchanging Data through userdata, if you could also write it all in one PyTag ?
            There should be no limitation using only one Python tag.

            Cheers,
            nux

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 20/05/2011 at 00:38, xxxxxxxx wrote:

              You're right, of course, but what I am experimenting with is kind of hard to explain and backwards to the smart way of doing things. The essence of it is to have a bunch of different pytags that do different tricks -- and for ease of use the user would drop one pytag per object depending on how they wanted the object affected. But all the different tags take cues from a master controller.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                On 20/05/2011 at 05:12, xxxxxxxx wrote:

                That's why you should write a Python Plugin.
                There, you can easily exchange data between all Tags in the Scene etc.

                Can you think of how to do that ? If not, I can share some example code for reference.
                Cheers, Niklas

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post