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

    IsConnected Method Not Working As Expected?

    Cinema 4D SDK
    2023 python
    2
    9
    835
    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.
    • B
      bentraje
      last edited by

      Hi,

      In the IsConnected documentation, it says If a true node is passed, every port on the node will be tested.

      I tried passing connected true node but it returns false, instead of true.

          with graph.BeginTransaction() as transaction:
      
              result = []
              GraphModelHelper.GetSelectedNodes(graph, maxon.NODE_KIND.ALL_MASK, result)
              print (result[0].GetKind()) # Returns #1 hence a true node
              debug = GraphModelHelper.IsConnected(result[0], result[0])
              print (debug) # Returns false. Should be True since the node is actually connected
              transaction.Commit()
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        The documentation is a bit confusing. The first parameter can be either a true-node or a port while the second parameter can only be a port. In your code you are passing two true-node and the same one result[0] so that could not work as a node cannot be connected to himself.

        You do not need to be on a transaction to read information, but just if you want to modify them.

        I will update the documentation. If you pass two ports, the function will check if they are connected. If you pass a true-node and a port. The connection with any output ports from the true node will be tested with the ports passed as the second parameter.

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • B
          bentraje
          last edited by

          @Manuel

          Thanks for the response.
          I was looking for a method/command to check if ANY of the ports of the node is connected.
          Use case is delete any unused nodes (i.e. no connected ports).

          Is there an available API for that?

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by Manuel

            hi,

            we do not have anything that could help here; you need to check for every port. Maybe the fatest way of doing it is to use GetDirectPredecessors and GetDirectSuccessors. This methods will search if there is a connection.
            There is a command to remove unused node in the node editor.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            B 1 Reply Last reply Reply Quote 0
            • B
              bentraje @Manuel
              last edited by

              @manuel

              Gotcha. Will try those commands,

              The "Remove Unused Nodes" is always grayed out when I'm using it. So I can't retrieve the call command in the script log.

              e53cccbc-0e6d-46d2-8f86-b6d6dcf097d9-image.png

              1 Reply Last reply Reply Quote 0
              • ManuelM
                Manuel
                last edited by Manuel

                hi,

                interesting, this is happening only on redshift material, the standard material and scene node, this is working as expected.

                    c4d.CallCommand(465002315) # Delete Unused Nodes
                

                Cheers,
                Manuel

                MAXON SDK Specialist

                MAXON Registered Developer

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by

                  This looks like a bug; it seems that, as the function does not find any node without any connection, the command is grey out. Seconde effect, the function will not work, even if called from outside.

                  I have opened a bug report for that. I am afraid that you do not have any way of checking that yourself.

                  Cheers,
                  Manuel

                  MAXON SDK Specialist

                  MAXON Registered Developer

                  1 Reply Last reply Reply Quote 1
                  • B
                    bentraje
                    last edited by

                    Hi @Manuel

                    Thanks for the follow up.
                    The GetDirectPredecessors and GetDirectSuccessors works for my use case.
                    Will close this thread now.

                    P.S. Just some minor nitpick, both method does not return the same type.
                    The first returns a list. While the second return an iterator.
                    Not really a problem per se since I can just convert the iterator to a list.
                    Just some FYI in case you are interested.

                    1 Reply Last reply Reply Quote 0
                    • ManuelM
                      Manuel
                      last edited by

                      @bentraje said in IsConnected Method Not Working As Expected?:

                      P.S. Just some minor nitpick, both method does not return the same type.
                      The first returns a list. While the second return an iterator.
                      Not really a problem per se since I can just convert the iterator to a list.
                      Just some FYI in case you are interested.

                      Thanks a lot for reporting that, we will fix this as soon as possible

                      MAXON SDK Specialist

                      MAXON Registered Developer

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