Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi, I'm New to Revit API and learning C# recently and below error comes to whileRun Program.
Anyone can help me.
"system.nullreferenceexception object reference"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace COBie_Door_Space
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
// Use OfCategory method to apply an ElementCategoryFilter and fine elements in the Doors category
FilteredElementCollector col = new FilteredElementCollector(doc);
ICollection<Element> doors = col.OfCategory(BuiltInCategory.OST_Doors).ToElements();
try
{
// Filtered element collector is iterable
foreach (Element e in doors)
{
FamilyInstance Fi = e as FamilyInstance;
Parameter getparam = Fi.LookupParameter("Comments");
using (Transaction tx = new Transaction(doc, "getparam"))
{
tx.Start("Parameter Exchange");
//set parameter
string s = Fi.FromRoom.Name;
getparam.Set(s);
tx.Commit();
}
}
return Result.Succeeded;
}
catch (Exception ex)
{
// Code did not execute successfully, display exception error
TaskDialog.Show("Exception Caught", "Exception: " + ex);
// return Failed
return Result.Failed;
}
}
}
}
Solved! Go to Solution.