Why getting HashSet instead of List?

Hi all !

I’m trying to retrieve the first view of each sheet (each of them containing 2 views). I got this warning but I don’t know the concept of HashSet (I found many results in Java but no one in python).


It may not be the easier way, any suggestion is welcome :slight_smile:

GetAllPlacedViews() returns a ISet. I guess a quick workaround is looping through what each set (a set of two views) while adding each view in it to your ViewListID list.

This is what I’m trying to do in the second loop but I get the warning shown above. It seems that I can’t loop thought an ISet.
Is it possible to cast/transform the ISet to a normal list ?

@raphael.georges1 you are adding a list of placed views into another list(ViewListID.append line). Then you are iterating over the initial list not the sublist.

GetAllPlaceViews gives you a Hashset of ElementID’s that you are then adding to a ViewListID list. Therefore ViewListID ends up becoming a list within a list.

Assuming the ViewListID loop is roughly where the warning appears i would suggest the following change:

Note: it should be a lower cast P for placeViews on my line 28

You can make a new Lisk from a HashSet like so:

someList = List[ElementId](someSet)

You should be able to iterate over a set, but bear in mind that they are not ordered. That means every time the order of items in a set might be different. Just FYI.

The error you are getting is related to you trying to call doc.GetElement() and feeding it a HashSet as an argument. It expects to get an ElementId or Reference.

Mistake is in this line: ViewListID.append(s.GetAllPlacedViews()) where GetAllPlacedViews() returns a HashSet object, and that is added to the list. Then when you iterate over that list your argument v is equal to HashSet. Perhaps instead of using append use extend. That will iterate over all items in a HashSet and add them to the list.


I tried your solution Brendan but I only retrieve the 2 lasts views.

Konrad’s solution worked fine with the extend() method, thank you !

The original goal was copy pasting a parameter from a view to a sheet and it worked, even if HashSet isn’t ordered.

1 Like