Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    how to control the on/off of a node in expresso?

    Cinema 4D SDK
    r20 python windows
    3
    9
    2.3k
    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.
    • M
      milkliu
      last edited by

      I want to control the on/off of a node in expresso.
      and i found the "on" attribute can do it.
      but I can't add the input port in python.
      anyone can help me ?
      thank you very much!

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @milkliu

        Please provides us more information about the initial setup and the expected behavior.
        Are you trying to control the enable state of the current python node, or any other nodes?
        Should these nodes be linked together?

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • merkvilsonM
          merkvilson
          last edited by

          I guess you want to create a node of the node.
          alt text

          M 1 Reply Last reply Reply Quote 1
          • M
            milkliu @merkvilson
            last edited by

            @merkvilson
            sorry๏ผŒI should put more information about my question.
            I want to add the "on" port in the gif below use python.

            alt text

            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by m_adam

              Do you want to add the port with a script from the script manager or a Python GvNode?

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              M 1 Reply Last reply Reply Quote 0
              • M
                milkliu @m_adam
                last edited by

                @m_adam I want to add it with a script from the script manager

                1 Reply Last reply Reply Quote 0
                • M
                  m_adam
                  last edited by m_adam

                  Hi @milkliu,

                  Unfortunately, I do have bad news, after some research it's currently not possible to add the "On" port in Python due to a bug.

                  With that's said here is an example of how to creates Node and Port in Xpresso. (As I said it does not work for the On port, and some generics ports so this example will currently not work)

                  import c4d
                  
                  
                  def main():
                      # Checks if selected object is valid
                      if op is None:
                          raise ValueError("op is none, please select one object.")
                  
                      # Retrieves the xpresso Tag
                      xpressoTag = op.GetTag(c4d.Texpresso)
                      if xpressoTag is None:
                          raise ValueError("Make sure the selected object get an Xpresso Tag.")
                  
                      # Retrieves the node master
                      gvNodeMaster = xpressoTag.GetNodeMaster()
                      if gvNodeMaster is None:
                          raise RuntimeError("Failed to retrieves the Node Master.")
                  
                      # Retrieves the Root node (the Main XGroup) that holds all others nodes
                      gvRoot = gvNodeMaster.GetRoot()
                      if gvRoot is None:
                          raise RuntimeError("Failed to retrieves the Root Node.")
                  
                      # Creates a Link node in the GvRoot
                      linkNode = gvNodeMaster.CreateNode(gvRoot, c4d.ID_OPERATOR_OBJECT, x=100, y=100)
                      if linkNode is None:
                          raise RuntimeError("Failed to creates the link Node.")
                  
                      # Defines the target of the link node to the host object of the Xpresso (in this case objHost, is the same as op)
                      objHost = linkNode.GetNodeMaster().GetOwner().GetObject()
                      linkNode[c4d.GV_OBJECT_OBJECT_ID] = objHost
                  
                      # Creates the "On" Port
                      onPort = None
                      if linkNode.AddPortIsOK(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_ON):
                          onPort = linkNode.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.GV_OBJECT_OPERATOR_ON)), c4d.GV_PORT_FLAG_IS_VISIBLE, True)
                  
                      if onPort is None:
                          raise RuntimeError("Failed to creates the On Port.")
                  
                      # Updates Cinema 4D
                      c4d.EventAdd()
                  
                  
                  if __name__ == '__main__':
                      main()
                  

                  Hopefully, it will be fixed in the next release, but I can't promise anything.
                  In any case, I will bump this thread when the fix is available.
                  Cheers,
                  Maxime.

                  MAXON SDK Specialist

                  Development Blog, MAXON Registered Developer

                  M 1 Reply Last reply Reply Quote 1
                  • M
                    milkliu @m_adam
                    last edited by

                    @m_adam Although I didn't get a solution to this problem, I found a solution to my own problem. Thank you very much.

                    1 Reply Last reply Reply Quote 0
                    • M
                      m_adam
                      last edited by m_adam

                      This issue is now fixed in R21.

                      Cheers,
                      Maxime.

                      MAXON SDK Specialist

                      Development Blog, MAXON Registered Developer

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