Finding nearest level

Finding nearest level

Anonymous
Not applicable
2,467 Views
4 Replies
Message 1 of 5

Finding nearest level

Anonymous
Not applicable

Hello everybody!

 

I am trying to find the nearest lower (and upper) level from a point.

 

I have been able to fint the nearest element (eg. a floor) using the next code:

 

ReferenceIntersector refIntersector = new ReferenceIntersector(view3D);
ReferenceWithContext referenceWithContext = refIntersector.FindNearest(elemPoint, new XYZ(0,0,-1));
Reference reference = referenceWithContext.GetReference();
XYZ lowerLevel = reference.GlobalPoint;

 

It finds the nearest element, but, unortunately, id does not find the nearest level.

I have tried using also it:

 

ElementClassFilter filter = new ElementClassFilter(typeof(Level));
ReferenceIntersector refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.All,view3D);

but it does not work....

 

 

 

Any idea??

 

Thanks in advance!

Chema

0 Likes
Accepted solutions (1)
2,468 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

Dear Chema,

 

Try this one. 

 

 

 

      private Level getNearestBelowLevel(double _Zvaue)
        {
            return new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().Where(x => x.Elevation < _Zvaue).OrderByDescending(x => x.Elevation).FirstOrDefault();
        }
        private Level getNearestUpperLevel(double _Zvaue)
        {
            return new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().Where(x => x.Elevation > _Zvaue).OrderBy(x => x.Elevation).FirstOrDefault();
        }

 

 

Note: In case of Shared co-ordinate Some time also use x.ProjectElevation instead of x.Elevation.

Message 3 of 5

Anonymous
Not applicable

Totally effective and much simpler!!!

 

Thanks So much!!!

Chema

0 Likes
Message 4 of 5

joshua.lumley
Advocate
Advocate

Thank you...so simple it is miraculous. 

0 Likes
Message 5 of 5

yoniblum
Explorer
Explorer

Is there an equivalent function to do this in python, where the input is the z-coordinate and the output is the nearest above level?

0 Likes