Compare items in list<dbcollection> if the same?

Compare items in list<dbcollection> if the same?

BIM_VIET
Enthusiast Enthusiast
801 Views
7 Replies
Message 1 of 8

Compare items in list<dbcollection> if the same?

BIM_VIET
Enthusiast
Enthusiast

I have a ListA - List<Dbcollection> with each item is a group of polylines (polyline have some property: Length, Xdata…):

List<Dbcollection> :

(0 - {poly1,  poly2, poly3…}, 

1 - {poly1,  poly2, poly3, poly4…},

2 - {poly1,  poly2, poly3…} …)

I would like to compare whether each item in ListA is the same together or not? Please help me how to do that.

Thanks in advance!

0 Likes
Accepted solutions (1)
802 Views
7 Replies
Replies (7)
Message 2 of 8

BIM_VIET
Enthusiast
Enthusiast

Any help?

0 Likes
Message 3 of 8

_gile
Consultant
Consultant

Hi,

Your question is not clear.

You should clarify what you want to achieve.

The type "Dbcollection" does not exist in the API.

What is the type of an item in ListA? a polyline? a list of polylines?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 8

BIM_VIET
Enthusiast
Enthusiast

@_gile ,

The type of ListA is List<DBObjectCollection>, DBObjectCollection is List of Polylines.

 

0 Likes
Message 5 of 8

_gile
Consultant
Consultant

OK, now you have to clarify what do you mean with: "I would like to compare whether each item in ListA is the same together or not?"

Do you want to evaluate if two DBObjectCollection contains the same DBObjects (Polylines)? in the same order?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 8

BIM_VIET
Enthusiast
Enthusiast

@_gile , 

Yes, that's what I want

0 Likes
Message 7 of 8

_gile
Consultant
Consultant

Does the order of polyline in the collection matters?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 8

_gile
Consultant
Consultant
Accepted solution

If the order of polylines in the collections does not matter, this shoul do the trick.

private static bool ContentsEqual(DBObjectCollection collection1, DBObjectCollection collection2) => 
        collection1.Count != collection2.Count &&
        !collection1.Cast<DBObject>().Except(collection2.Cast<DBObject>()).Any();

If the order matters use this instaed.

private static bool OrderedContentsEqual(DBObjectCollection collection1, DBObjectCollection collection2)
{
    if (collection1.Count != collection2.Count)
        return false;
    for (int i = 0; i < collection1.Count; i++)
    {
        if (collection1[i] != collection2[i])
            return false;
    }
    return true;
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes