Search objects by type and name function API

Issue #203 resolved
Ali Ozdemir created an issue

Public Function SearchObjectByTypeAndName(type As String, name As String) As OBrIMObj

Above function only searches current level. It would be helpful if there is an API call which can search child objects also. It can return to list of OBrIMObj if there is more than one object.

Comments (2)

  1. Ali Koc

    Actually, despite its name, SearchObjectByTypeAndName function seems to be only matching types and ignoring name. This seems to be a bug corrected in v3.160604.

    Added another function which does the same thing recursively. Look for SearchObjectByTypeAndNameDeep function. The implementation is fairly simple. In case you need to search objects by other criteria in the future, I am pasting the code here, you can customize and use:

            public static void SearchObjectByTypeAndNameDeep(OBrIMObj o, string type, string name, List<OBrIMObj> ret)
            {
                if (type == o.ObjType && o.Name == name) ret.Add(o);
                for (int i = 0; i < o.Objects.Count; i++)
                    SearchObjectByTypeAndNameDeep(o.Objects.Get(i), type, name, ret);
            }
    
  2. Log in to comment