Levels from document do not match levels from viewplans

Levels from document do not match levels from viewplans

Anonymous
Not applicable
802 Views
3 Replies
Message 1 of 4

Levels from document do not match levels from viewplans

Anonymous
Not applicable

I am working on a utility to quickly jump up or down a level in a project. I have run into an issue where I have collected and sorted by elevation all the levels in a project

 

        private List<Level> GetAllLevels()
        {
            FilteredElementCollector levelCollector = new FilteredElementCollector(m_doc);
            List<Level> levelCollection = levelCollector.OfClass(typeof(Level)).OfType<Level>().OrderBy(l => l.Elevation).ToList();
            return levelCollection;
        }

I then am comparing the levels to the active views level. (I am ensuring first that the active view is a plan view)

 

Level currentLevel = doc.ActiveView.GenLevel;

A match is never found for the levels.

 

The attached image is from the Locals window of VS. projectLevel is the level in the loop, and currentLevel is the level of the active view. They appear to be the same, but are not a match.  Why?

 

I could try to match elevation of the levels, or the AssociatedPlanViewId of the level, but I thought that they should be the same object.

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

BobbyC.Jones
Advocate
Advocate

Match on Id's of the levels, not the levels themselves.

--
Bobby C. Jones
0 Likes
Message 3 of 4

Anonymous
Not applicable

Unfortunately, the LevelId property always returns -1.  I am currently using the Name Property, since it looks like it has to be unique.

0 Likes
Message 4 of 4

BobbyC.Jones
Advocate
Advocate
Accepted solution

For Level elements, just use the Id property, not LevelId.

--
Bobby C. Jones