SOLVED IsConnected Method Not Working As Expected?

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()

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

@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?

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

@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

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

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

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.

@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