Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to retrieve a level id in active view?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
nur91m
8713 Views, 9 Replies

How to retrieve a level id in active view?

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

Tags (2)
9 REPLIES 9
Message 2 of 10
Troy_Gates
in reply to: nur91m

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
in reply to: Troy_Gates

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.

 

 

Message 4 of 10
Troy_Gates
in reply to: Anonymous

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();
Message 5 of 10
Anonymous
in reply to: Troy_Gates

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.

 

 

 

Message 6 of 10
adcdao
in reply to: nur91m

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é

Message 7 of 10
adcdao
in reply to: Troy_Gates

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é

Message 8 of 10
logimep
in reply to: adcdao

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.

Message 9 of 10
guillain.jolivet
in reply to: adcdao

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
in reply to: guillain.jolivet

Thank you, it's working very well!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report