<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: system.nullreference exception object reference in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987281#M29203</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1035859"&gt;@RPTHOMAS108&lt;/a&gt;&amp;nbsp; Thanks now it's&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; Working!!.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#region Namespaces
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;
#endregion

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);
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
            IList &amp;lt;Element&amp;gt; doors = col.WherePasses(filter).WhereElementIsNotElementType().ToElements();

            try
            {
                // Filtered element collector is iterable
                foreach (Element e in doors)
                {

                  Parameter getparam = e.LookupParameter("COBie.Component.Space");

                    using (Transaction tx = new Transaction(doc, "getparam"))
                    {
                        tx.Start("Parameter Exchange");

                        //set parameter
                        FamilyInstance Fi = e as FamilyInstance;
                        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;
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 08 Jan 2021 13:35:16 GMT</pubDate>
    <dc:creator>T52K-BIB</dc:creator>
    <dc:date>2021-01-08T13:35:16Z</dc:date>
    <item>
      <title>system.nullreference exception object reference</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987096#M29201</link>
      <description>&lt;P&gt;hi, I'm New to Revit API and learning C# recently and&amp;nbsp;below error comes to whileRun Program.&lt;/P&gt;&lt;P&gt;Anyone can help me.&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;"system.nullreferenceexception object reference"&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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&amp;lt;Element&amp;gt; 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;
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 12:05:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987096#M29201</guid>
      <dc:creator>T52K-BIB</dc:creator>
      <dc:date>2021-01-08T12:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: system.nullreference exception object reference</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987148#M29202</link>
      <description>&lt;P&gt;NullReferenceException is the most popular exception by far and a personal favourite of mine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume it is occurring at a location where you’ve declared an object but not given it a value such as:&lt;BR /&gt;FamilyInstance Fi = e as FamilyInstance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your collector has FamilySymbols and FamilyInstances as you’ve not set .WhereElementIsNotElementType. Traditionally this would cause InvalidCastException (my second favourite exception) but with the ‘as’ keyword it masks the problem resulting in a null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So when you later use a member of Fi you get NullReferenceException.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 12:40:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987148#M29202</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-01-08T12:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: system.nullreference exception object reference</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987281#M29203</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1035859"&gt;@RPTHOMAS108&lt;/a&gt;&amp;nbsp; Thanks now it's&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; Working!!.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#region Namespaces
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;
#endregion

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);
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
            IList &amp;lt;Element&amp;gt; doors = col.WherePasses(filter).WhereElementIsNotElementType().ToElements();

            try
            {
                // Filtered element collector is iterable
                foreach (Element e in doors)
                {

                  Parameter getparam = e.LookupParameter("COBie.Component.Space");

                    using (Transaction tx = new Transaction(doc, "getparam"))
                    {
                        tx.Start("Parameter Exchange");

                        //set parameter
                        FamilyInstance Fi = e as FamilyInstance;
                        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;
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 08 Jan 2021 13:35:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/system-nullreference-exception-object-reference/m-p/9987281#M29203</guid>
      <dc:creator>T52K-BIB</dc:creator>
      <dc:date>2021-01-08T13:35:16Z</dc:date>
    </item>
  </channel>
</rss>

