Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Search only visible items and exclude items that has a hidden parent

Anonymous

Search only visible items and exclude items that has a hidden parent

Anonymous
Not applicable

Hi,

 

I want to make a Search() that finds all visible items in a document. I also want the search to take into account if the object has a hidden parent, grandparent or higher level node. In that case the item would be excluded from the search result. Is there a way to do this directly using the Search API?

 

I would prefer not to iterate over every item and traverse its parents to find out if the item is hidden hierarchically.

 

Best regards,

Elias Furenhed

Reply
1,309 Views
5 Replies
Replies (5)

xiaodong_liang
Autodesk Support
Autodesk Support

Hi Elias,

 

you could use LINQ which allows to find items with more expressions. e.g.

 

IEnumerable<ModelItem>items = 
from x in oDoc.Models[0].RootItem.DescendantAndSelf
where x.Parent.isHidden
select x;

oDoc.CurrentSelection.CopyFrom(items);

or Search also supports LINQ, e.g.

 

IEnumerable<ModelItem>items = 
search.FindAll(oDoc.false).Where(x=>x.parent.isHidden);

oDoc.CurrentSelection.CopyFrom(items);

 

Anonymous
Not applicable

Hello,

Okay, what if the parent is not hidden but the grandparent is? Then I would need to check visiblility for every parent all the way up to the root, right? If I have a very large amount of objects, then it would be slow to do that check for each object. Am I correct that there is no way of using the "hierarchical visibility" i.e. object has a hidden node anywhere above itself directly in the search?

 

/Elias

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

maybe i missed something, but, with my experience, if a node is node hidden, its parent ,ancestors will not be hidden. otherwise, it would be contradict. you could verify by this in UI. 

 

probably it would be better you could describe a bit more on your requirement beyond the technical detail, then we could think about if there is any other ways.

0 Likes

shayne.kiekebosch
Participant
Participant

Hello, sorry to bring up an old thread but I have this exact same problem and it wasn't answered/solved. The issue is that if an items parent, or grandparent or even higher-level-node, has IsHidden = true then the original item is hidden but has IsHidden = false.

 

I'll try illustrate it here:

ItemA

- ItemB

-- ItemC

 

ItemC is a child of ItemB and ItemB is a child of ItemA. In this case, if ItemA has IsHidden = true, then all the child items are not visible but have IsHidden = false. So the only way for us to determine if the item is actually hidden or not is to go through it's parent(s) all the way to the root node. For example, if we want to know if ItemC is visible we would have to check it's parents IsHidden, then check that parents IsHidden:

 

 

bool isItemCHidden = false;
if (!ItemC.IsHidden)
{
    var parent = ItemC.parent;
    while (parent != null)
    {
        if (!parent.IsHidden)
            parent = parent.parent;
        else
        {
            isItemCHidden = true;
            break;
        }
    }
}

 

 

Currently our best option is to start with the root node, continue down all children and ignore all nodes that have IsHidden = true. We don't bother going down their children since they aren't visible.

 

It would be great if there was a property like "IsVisible" that will state whether the item is visible to the user. Then we could do a search which should be much quicker and less code.

 

Happy to start a new thread if need be.

alexisDVJML
Collaborator
Collaborator

Also very interested with such feature.

Going up the ancestors is very slow.
Below a method that speed up a bit checking if any ancestor is hidden.
I still have to find a better way, and working on it.

I will post an update if I find anything.

 

static public bool AnyParentHidden2(ModelItem anItem)
{
	InwOaPath path = ComApiBridge.ToInwOaPath(anItem);
	InwPathNodesColl nodes = path.Nodes();
	int c = nodes.Count;
	for (int i = 1; i != c; i++)
	{
		if (((InwOaNode)nodes[i]).IsOverrideHide)
			return true;
	}
	GC.KeepAlive(nodes);
	GC.KeepAlive(path);

	return false;
}

 

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes