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

    Change Xpresso Object Node Ref with Python

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 878 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

      On 18/02/2018 at 01:00, xxxxxxxx wrote:

      Hi
      i have a scene with a null, a cube and a sphere,
      that null has a xpresso tag on it and a bunch of user data sliders
      inside xpresso i made connections between null user data and an object node named "MyObject" referenced to the cube which controls cube's position;
      is it possible to change that "MyObject" node reference from cube to sphere with a python script?

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

        On 19/02/2018 at 08:59, xxxxxxxx wrote:

        Hi,

        welcome to the Plugin Café forums !Smile[URL-REMOVED]

        Actually you don't need any scripting at all to achieve this.

        Here's option one to solve it in Xpresso, just by assigning another object to an object node:
        ![]([URL-REMOVED]

        In order to avoid the above mentioned downside, you can use an object reference node, see here:
        ![]([URL-REMOVED]

        And then lastly, if you want to do it in Python, there's GvNode.OperatorSetData(), which can be used to assign another object to an object node. The mode to use there is GV_OP_DROP_IN_BODY.


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

          On 19/02/2018 at 10:46, xxxxxxxx wrote:

          Hi Andreas,
          Thanks!
          actually switch node is a perfect solution for this example
          but my real situation is a bit more complicated and i think python is the only way!
          that GvNode.OperatorSetData() helped me but now i don't know how to use it for that specific node named "MyObject" Confused

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

            On 20/02/2018 at 02:31, xxxxxxxx wrote:

            Hi,

            so you basically need to get hold of the GvNode "MyObject".
            There are different ways to achieve this, also depending on where you implement it (in a Python Scripting node or a Script Manager script or ...). The following function should help with this: XPressoTag.GetNodeMaster(), GvNodeMaster.GetRoot() (and from there with the usual GeListNode tools).

            And then it's just calling OperatorSetData(), roughly like so:

            myObjNode.OperatorSetData(c4d.GV_ATOM, theOtherObject, c4d.GV_OP_DROP_IN_BODY)
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 20/02/2018 at 08:05, xxxxxxxx wrote:

              Thanks Andreas
              i finally got it workin'
              that last step could also be achieved by setting GV_OBJECT_OBJECT_ID directly 🙂
              this is the final code:

              import c4d
              def main() :

              Cube = doc.SearchObject('Cube')
              Remote = doc.SearchObject('Remote') #user data holder
              RemoteXP = Remote.GetTag(c4d.Texpresso)
              RemoteNodes = RemoteXP.GetNodeMaster()
              Root = RemoteNodes.GetRoot()
              MyNodes = Root.GetChildren()
              for child in MyNodes:
              if child[c4d.ID_BASELIST_NAME] == 'MyObject':
              child[c4d.GV_OBJECT_OBJECT_ID] = Cube
              #child.OperatorSetData(c4d.GV_ATOM, Cube, c4d.GV_OP_DROP_IN_BODY)

              doc.EndUndo()
              c4d.EventAdd()

              if __name__=='__main__':
              main()

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