revit encountered a system.nullreferenceexception object reference not set to ob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i have this code for import from excel data to revit this is my code:
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
//Application app = uiapp.Application;
Document doc = uidoc.Document;
string fileman = Path.Combine(Path.GetTempPath(), "MyExcelbad.xlsx");
using (Transaction t = new Transaction(doc, "param"))
{
t.Start();
using (ExcelPackage package = new ExcelPackage(new FileInfo(fileman)))
{
ExcelWorksheet sheet = package.Workbook.Worksheets["Wall"];
foreach (WallType elem in new FilteredElementCollector(doc).OfClass(typeof(WallType)).WhereElementIsElementType())
{
//stacked don't have cost
if (elem.Kind == WallKind.Stacked)
{
continue;
}
for (int value = 2; value <= sheet.Dimension.Rows; value++)
{
if (sheet.Cells[value, 1].Value.Equals(elem.Name))
{
if (sheet.Cells[value, 1].Value.Equals("Exterior - Brick on Mtl. Stud"))
{
continue;
}
if (sheet.Cells[value, 1].Value.Equals("Exterior - Block on Mtl. Stud"))
{
continue;
}
sheet.Cells[value, 8].Value = elem.Name;
if (null != elem.get_Parameter(BuiltInParameter.ALL_MODEL_COST))
{
Parameter cost = elem.get_Parameter(BuiltInParameter.ALL_MODEL_COST);
cost.Set(sheet.Cells[value, 4].Value.ToString());
elem.get_Parameter(BuiltInParameter.KEYNOTE_PARAM).Set(10);
}
}
}
}
package.Save();
}
t.Commit();
}
return Result.Succeeded;
}
but i have this error
i dont know why this error happened for me
this is line 64
: