getting keynote parameter issue

getting keynote parameter issue

wahedfazeli
Enthusiast Enthusiast
1,304 Views
3 Replies
Message 1 of 4

getting keynote parameter issue

wahedfazeli
Enthusiast
Enthusiast

i want to get all keynotes of elements of my project i write this code but i dont know why this create error in my revit i want to transfer it to excel.

row=2;

foreach(Element e in new FilteredElementCollector(doc).OfClass(typeof(Wall)))

{

ElementType elem = doc.GetElement(e.Id) as ElementType;

Parameter p = elem.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);

sheet.Cells[row, 4].Value = p.ToString();

row++;;

}

 

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

FAIR59
Advisor
Advisor

the line to get the walltype isn't correct. Use this instead

 

ElementType elem = doc.GetElement(e.GetTypeId()) as ElementType;

 

You might want to rethink your code. By collecting wall instances, you get the same walltype (and keynote value) multiple times.

You can get all the defined walltypes in the document like this:

 

			ElementMulticategoryFilter wallfilter = 
				new ElementMulticategoryFilter(new List<BuiltInCategory>(){BuiltInCategory.OST_Walls,BuiltInCategory.OST_StackedWalls});
			IEnumerable<ElementType> walltypes = new FilteredElementCollector(doc)
				.WhereElementIsElementType()
				.WherePasses(wallfilter)
				.Cast<ElementType>();
0 Likes
Message 3 of 4

wahedfazeli
Enthusiast
Enthusiast
Thanks for your solution

But i want to put all keynotes parameters in every cells of excel
I should use for or foreach loop to get every keynote parameter and use it
I dont use transaction .can it be my problem?
Thank you
0 Likes
Message 4 of 4

FAIR59
Advisor
Advisor
Accepted solution

As you only read the document, you don't need a transaction.

this is the corrected code:

			foreach(Element e in new FilteredElementCollector(doc).OfClass(typeof(Wall)))
			{
				ElementType elem = doc.GetElement(e.GetTypeId()) as ElementType;
				Parameter p = elem.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);
				sheet.Cells[row, 4].Value = p.AsString();
				row++;;
			}