How many relations match a string?

I’d like to get a count of relations in a physical model that match a particular string. I see a “GetObjectByName” function, but it doesn’t seem to return a count. I’d like to be able to do something like:

  • Model.Relations.GetObjectByName(“MyRelationName”).Count
    How would I achieve this?

Hi Eric,

It is not usually, because it is not correct state, when in this list is more than one object with same name. List has not this method, but you can write simple function. See code:

function GetObjCountByName(Name, List)
{
var i, Obj;
var Result = 0;
for (i=0;i<List.Count;i++)
{
Obj = List.GetObject(i);
if (Obj.Name==Name)
Result += 1;
}
return Result;
}

function main(){
var List = Model.Relations;
var c = GetObjCountByName(‘Relationship1’, List);
Log.Information('Count is: '+c);
}

Daril