Get grids form PickObjects Selection

Get grids form PickObjects Selection

luisdavid.mena
Enthusiast Enthusiast
792 Views
3 Replies
Message 1 of 4

Get grids form PickObjects Selection

luisdavid.mena
Enthusiast
Enthusiast

Hello

How can I get Grids from a List of Elements that I got with PickObjects method?

IList<Element> elemen_x = new List<Element>();
Selection sel = uidoc.Selection;
var axis_x = sel.PickObjects(ObjectType.Element).ToList();
foreach(Reference e in axis_x)
{
	var ele = doc.GetElement(e);
	elemen_x.Add(ele);
}

 

0 Likes
Accepted solutions (1)
793 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor
Accepted solution
0 Likes
Message 3 of 4

Sean_Page
Collaborator
Collaborator

If you only want grids you can use the ISeletionFilter.

https://www.revitapidocs.com/2015/8038c1e1-262e-5d25-c065-b75b9ba98603.htm

 

Or you can use if check to see if it's a grid:

foreach(Reference e in axis_x)
{
	If(doc.GetElement(e) is Grid grid)
        {
	    elemen_x.Add(grid);
        }
}

 

 

 

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 4 of 4

luisdavid.mena
Enthusiast
Enthusiast

Thanks @RPTHOMAS108  . It was indeed the casting to Grids. Also what you suggest @Sean_Page  is very usefull for me!

0 Likes