How to retrieve a level id in active view?

How to retrieve a level id in active view?

nur91m
Advocate Advocate
9,291 Views
9 Replies
Message 1 of 10

How to retrieve a level id in active view?

nur91m
Advocate
Advocate

I want to create wall in the active view. Wall.Create() method has levelId. So how can I retrieve a level id in active view?

Thanx

0 Likes
Accepted solutions (1)
9,292 Views
9 Replies
Replies (9)
Message 2 of 10

Troy_Gates
Advocate
Advocate
Accepted solution

Here is a quick macro I wrote that gets the active view's level id

 

public void ViewLevel()
{
	Document doc = ActiveUIDocument.Document;			
	View active = doc.ActiveView;
	ElementId levelId = null;
	
	Parameter level = active.LookupParameter("Associated Level");
	
	FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
	ICollection<Element> lvlCollection = lvlCollector.OfClass(typeof(Level)).ToElements();
	
	foreach (Element l in lvlCollection)
	{
		Level lvl = l as Level;				
		if(lvl.Name == level.AsString())
		{
			levelId = lvl.Id;
			//TaskDialog.Show("test", lvl.Name + "\n"  + lvl.Id.ToString());
		}
	}

}

 

Message 3 of 10

Anonymous
Not applicable

If I want to add level name form the active view to the drop down list of the windows form How I do that?

 

for example:- I creating addin after clicking the addin button it open the windows form.It contains the dropdown list. I want to add the name of the levels from the active view of the revit.

 

 

0 Likes
Message 4 of 10

Troy_Gates
Advocate
Advocate

I'm not sure why you would want to use a drop down list when there can only be one level per view. But in the example above, you can use the first part to get the active view's level name...

 

 

Document doc = ActiveUIDocument.Document;			
View active = doc.ActiveView;
Parameter level = active.LookupParameter("Associated Level");
String levelName = level.AsString();
0 Likes
Message 5 of 10

Anonymous
Not applicable

I am using drop down list because I creating addin which contains 2 dropdown list and one button. First drop down contains item "Join wall and column" and second drop down contain levels like (first floor level, second floor level etc)

 

If I select both item and click on button it only joins those wall and column which is in that level which I have been selected.

 

 

 

0 Likes
Message 6 of 10

adcdao
Advocate
Advocate

Hi, I'm using a French version of Revit so I have to use "Niveau associé" in place of "Associated level". Is there a builtin parameter I can use?

 

Thanks,

André

0 Likes
Message 7 of 10

adcdao
Advocate
Advocate

Hi, I'm using a French version of Revit so I have to use "Niveau associé" in place of "Associated level". Is there a builtin parameter I can use?

 

Thanks,

André

0 Likes
Message 8 of 10

logimep
Participant
Participant

Hi, you should install Revit lookup plugin. You will snoop your wall parameters and then snoop the parameter you want, you will find a BuiltInParameter correspondance.

0 Likes
Message 9 of 10

guillain.jolivet
Contributor
Contributor

You can do that whithout using LookupParameter method using only API methods and properties. No language problem.

 

Document doc = uiapp.ActiveUIDocument.Document;
View activeView = doc.ActiveView;
Level level = activeView.GenLevel;
ElementId levelId = level.Id;
string levelName = level.Name;

 

Message 10 of 10

adcdao
Advocate
Advocate

Thank you, it's working very well!

0 Likes