HasConnectedInput 2.0 sdk

what is the new way to check if a port has a connection. the HasConnectedInput method does not look to be in there anymore

I’m going to give this a stab in the dark by using the API docs (I haven’t actually tried) , but if you get the port model from the node by using the InPorts property…

http://dynamods.github.io/DynamoAPI/Dynamo_Graph_Nodes/NodeModel/

You can then get connector model from the port you’re interested in by using the connector property…

http://dynamods.github.io/DynamoAPI/Dynamo_Graph_Nodes/PortModel/

If this is null, then I guess it’s not connected.

This is just a guess though and might be a better way. I’ll try a little later on as I haven’t done this yet.

1 Like

@Daniel_Woodcock1 thanks I definitely saw that and can use a few different methods to rebuild a function that does the same thing as hasconnextedinput but just wondering why that went away.

I am wondering if there is a new approach to this in 2.0. there is still a ton of issue I have with the design of node model and how convoluted it is to interact with the inputs and outputs.

No worries @Robert_Cervellione1, shame I couldn’t be more help, I’m pretty new to the API. Not sure why it went though, maybe to better separate the different models. Maybe the Dynamo Tests github pages might shed some light?

Hello All,
Just wondering if there is any updates for this.
What is the alternate way?

Thank you!

From glancing at the dynamo github source code, I’d say you can get this from the node’s NodeModel. From the NodeModel you can get the InPorts/Out Ports which will give a collection or PortModels which you could filter by name or ID and on the PortModel there is a property “IsConnected” that sounds like what you need.

This is untested (not near a PC atm), but feel free to take a look at the source code yourself as this holds all the answers :blush:…

Hope this helps.
Dan

3 Likes

from the source code I got something and changed it and used it in my code:

private ObservableCollection<PortModel> inPorts = new ObservableCollection<PortModel>();
internal bool IsAnyInputDisconnected
{			
get
	{
		if (inPorts != null && inPorts.Count > 0)
		{
			return inPorts.Any((PortModel p) => !p.IsConnected);
		}
		return false;
	}
}
2 Likes

Good stuff, glad you found a solution.

1 Like