Getting levelId for Level below from viewrange returns -4

Getting levelId for Level below from viewrange returns -4

Anonymous
Not applicable
1,798 Views
3 Replies
Message 1 of 4

Getting levelId for Level below from viewrange returns -4

Anonymous
Not applicable

Hi,

 

Im trying to retrieve information about view depth from the PlanViewRange object for a specific level.

So first I try to get the elementId of all levels.
However one level returns -4, what is that? -1 is Invalid elementid, but -4?

 

This is my code:

            var view = new FilteredElementCollector(Document).OfClass(typeof(ViewPlan)).FirstOrDefault(x=>x.Name=="Level 1");
            
            var viewRange = ((ViewPlan)view).GetViewRange();
            
            var bottomLevel = viewRange.GetLevelId(PlanViewPlane.BottomClipPlane);
            

Im trying this in the basic sample file, and the setting for the bottom clipplane is view below. There is a view below the level associated with the view. When I try level above, it works as expected.

Revit lookup tells me the the level for the bottom clip plane is null.

 

Any thoughts?

Thanks

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

matthew_taylor
Advisor
Advisor
Accepted solution

Hi Erik,

I remember muddling through this in the past, so here goes:

 

If bottomLevelId.IntegerValue = -1 Then
            'unlimited view depth
ElseIf bottomLevelId.IntegerValue = -3 Then
            'the same as the plan level
ElseIf bottomLevelId.IntegerValue = -4 Then
            'the level below the plan level
End If

If topLevelId.IntegerValue = -1 Then
            'unlimited view depth
ElseIf topLevelId.IntegerValue = -2 Then
            'the level above
ElseIf topLevelId.IntegerValue = -3 Then
            'the same as the plan level
End If

 

I had to manually work out the levels. To do this I just got a list of the levels sorted by elevation, and selected the appropriate one. I think I got the levels from existing plans, so the list omitted all non-plan intermediate levels.

 

    ''' <summary>
    ''' Returns a sorted list of level objects that have been used for a plan view.
    ''' </summary>
    ''' <param name="doc"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetAllPlanLevels(ByVal doc As DB.Document) As List(Of DB.Level)
        Dim collector As New DB.FilteredElementCollector(doc)
        Dim comparer As New EqualityComparerLevel
        Dim levels As List(Of DB.Level) = collector.OfClass(GetType(DB.ViewPlan)).Cast(Of DB.ViewPlan).Where(Function(v) _
                              Not v.IsTemplate AndAlso v.GenLevel IsNot Nothing).Select(Function(vp) vp.GenLevel).Distinct(comparer).ToList

        'Dim allLevels As New List(Of DB.Level)
        'For Each lev As DB.Level In levels

        '    allLevels.Add(lev)
        'Next
        levels = levels.OrderBy(Function(item) item.Elevation).ToList()
        Return levels
    End Function


Public Class EqualityComparerLevel
    Implements IEqualityComparer(Of DB.Level)

    Public Function Equals1(x As DB.Level, y As DB.Level) As Boolean Implements IEqualityComparer(Of DB.Level).Equals
        Return x.Id.IntegerValue.Equals(y.Id.IntegerValue)
    End Function

    Public Function GetHashCode1(obj As DB.Level) As Integer Implements IEqualityComparer(Of DB.Level).GetHashCode
        Return obj.Id.GetHashCode
    End Function
End Class

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 4

Anonymous
Not applicable

Hi Matthew!

 

Excellent, and quick answer!
I just cannot believe that this functionality, added in 2013, is not documented.

OR, that the api would just return the levelid and not some obscure reference. The UI tells the user what level is below or above.
After some testing it seems like there is some inconsistency: the elementid for the level below returns -4, but the elementid for the level above returns the actual elementid.

 

I was suspecting that this could be the case, but thank you for confirming and mapping out what the different "elementid" are pointing to.

 

0 Likes
Message 4 of 4

matthew_taylor
Advisor
Advisor

Hi Erik,

You're welcome! It took a bit of figuring out though, so I'm happy to save you the time.

I also think it should be documented.

I do understand why it is like this though. View templates. It's a way for the view range to be included in view templates and still work.

 

Cheers,

 

-Matt

 

p.s. note that I've edited out the 'use bottom level' and 'use top level' comments from my code post. I think that was just for the application I needed it for.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes