[Solved] Iterating through GoObjects in GoView.Document

Hello,

I have a GoView control with a few GoGeneralNode objects added to it on multiple occasions.

Each Node when added to the GoDocument sheet is set with a unique identifier as its Tag property.

I’m trying to find a node based on what Tag property value it holds but unfortunately couldn’t do so. As of now, there are 2 ways to find a Node on the document (using FindNode() or FindPart()) but both of them are ineffective in my situation since Nodes might use the same Text value or other reasons as such.

Essentially, I’m trying to do something along the lines of:

foreach(var object in goView1.Document.<?objects collection maybe?>)
{
     if (object is GoGeneralNode gn)
     {
            if (gn.Tag == <something unique>)
            {
                         Console.WriteLine("Found matching Node object");
            }
     }
}

Unfortunately, I’m unable to find a way to get all the GoObjects in a Document so that I can later iterate through them and find a specific node. Any help is appreciated, Thanks!

I’ve fixed it, quite embarrassing to have missed something so obvious, my bad!

Here’s what I did to fix it:

foreach(var obj in goView1.Document)
{
	if (obj is GoGeneralNode my_node)
	{
		if (my_node.Tag == <MyTag>)
		{
            Console.WriteLine("This was the specific node I was looking for!");
			Console.WriteLine("It worked!");
		}
	}
}

Correct. GoDocument, GoLayer, GoGroup, GoCollection all implement IGoCollection. And GoSelection is a GoCollection.