<?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: Rebar selected column in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11658934#M14776</link>
    <description>&lt;P&gt;Can you step through and debug?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2023 11:56:03 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2023-01-05T11:56:03Z</dc:date>
    <item>
      <title>Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11650995#M14770</link>
      <description>&lt;P&gt;Hello forum.&lt;/P&gt;&lt;P&gt;I'm trying to code a program in order to rebar a selected column from the user using "Create From Curves", but i found a problem, when I execute the code an error message was shown :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;EM&gt;"Référence d'objet n'est pas définie a une instance d'un objet"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The RebarBarType argument was extracted from a selected rebar&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Source Code :&lt;/P&gt;&lt;LI-CODE lang="general"&gt;try
            {
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document; ;

                //select the column
                Reference reff = uidoc.Selection.PickObject(ObjectType.Element);
                ElementId idd = reff.ElementId;
                FamilyInstance P1 = doc.GetElement(idd) as FamilyInstance;

                //select the rebar
                Reference reff2 = uidoc.Selection.PickObject(ObjectType.Element);
                ElementId idd2 = reff2.ElementId;
                Rebar P2 = doc.GetElement(idd2) as Rebar;
                //get the rebar bar type 
                RebarBarType RT = P2.Document.GetElement(P2.GetTypeId()) as RebarBarType;
                

                using (Transaction trns = new Transaction(doc,"Rebar"))
                {
                    trns.Start();

                    LocationPoint location = P1.Location as LocationPoint;
                    XYZ origin = location.Point;
                    XYZ normal = new XYZ(1, 0, 0);
                    XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 2);
                    Line rebarLine = Line.CreateBound(origin, rebarLineEnd);
                    IList&amp;lt;Curve&amp;gt; curves = new List&amp;lt;Curve&amp;gt;();
                    curves.Add(rebarLine);

                    Rebar rebar = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, RT, null, null,
                                      P1, normal, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);
                    
                     trns.Commit();
                      }

                      return Result.Succeeded;
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        TaskDialog.Show("error",message);
                        return Result.Failed;
                    }&lt;/LI-CODE&gt;&lt;P&gt;But i can't locate the source of the problem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 16:12:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11650995#M14770</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-01-01T16:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11651018#M14771</link>
      <description>&lt;P&gt;Happy New Year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before addressing your question, some advice on programming in general: I suggest you always clearly separate the UI from the calculation, and the calculation from the model modification. So:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Put the call to &lt;U&gt;PickObject&lt;/U&gt; in its own &lt;U&gt;separate&lt;/U&gt; exception handler (since an exception is thrown if the user cancels the selection)&lt;/LI&gt;
&lt;LI&gt;Perform the calculation step to define the list of curves&lt;/LI&gt;
&lt;LI&gt;Start the transaction and perform the rebar creation&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, I would suggest adding a selection filter derived from&amp;nbsp;the &lt;U&gt;ISelectionFilter&lt;/U&gt; interface to your pick method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.revitapidocs.com/2023/d552f44b-221c-0ecd-d001-41a5099b2f9f.htm" target="_blank"&gt;https://www.revitapidocs.com/2023/d552f44b-221c-0ecd-d001-41a5099b2f9f.htm&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will guarantee that the selected object really is what you expect, and simplify the picking for the user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, to address your question: maybe the user picked the wrong object. Maybe P@ or RT end up null. Debug through your code step by step interactively in the debugger and you will see which statement is causing the error. Then it will become obvious how it can be fixed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 16:42:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11651018#M14771</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-01-01T16:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11653749#M14772</link>
      <description>&lt;P&gt;Thank you for the answer.&lt;/P&gt;&lt;P&gt;I try to use a selection filter of selection. And to make sure, I put a message box if the Rebar Type found or not.&lt;/P&gt;&lt;P&gt;but the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;try
            {
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document; ;
                RebarBarType RT = null;

                Reference reff = uidoc.Selection.PickObject(ObjectType.Element);
                ElementId idd = reff.ElementId;
                FamilyInstance P1 = doc.GetElement(idd) as FamilyInstance;

                var all_rebar_types =new FilteredElementCollector(doc)
                    .OfCategory(BuiltInCategory.OST_Rebar).WhereElementIsElementType()
                    .ToElements();
                
                foreach (var rebar_type in all_rebar_types)
                {
                    string rebar_name = rebar_type.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString();
                    if (rebar_name == "01")
                    {
                        RT = rebar_type as RebarBarType;
                        TaskDialog.Show("Message", "01 Exist");
                        break;
                    }
                        
                }

                using (Transaction trns = new Transaction(doc,"Rebar"))
                {
                    trns.Start();

                    LocationPoint location = P1.Location as LocationPoint;
                    XYZ origin = location.Point;
                    XYZ normal = new XYZ(1, 0, 0);
                    XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 2);
                    Line rebarLine = Line.CreateBound(origin, rebarLineEnd);
                    IList&amp;lt;Curve&amp;gt; curves = new List&amp;lt;Curve&amp;gt;();
                    curves.Add(rebarLine);


                    Rebar rebar = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, RT, null, null,
                                      P1, normal, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);
                    

                trns.Commit();
                }
                return Result.Succeeded;
             }
             catch (Exception ex)
            {
            message = ex.Message;
            TaskDialog.Show("error",message);
            return Result.Failed;
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 Jan 2023 09:55:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11653749#M14772</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-01-03T09:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11653794#M14773</link>
      <description>&lt;P&gt;Oh dear, how sad. Happy New Year anyway!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I searched The Building Coder for&amp;nbsp;&lt;U&gt;CreateFromCurves&lt;/U&gt; and found:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2014/12/the-building-coder-wishes-you-a-merry-christmas.html" target="_blank"&gt;The Building Coder wishes you a Merry Christmas!&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2018/10/resources-rotated-rebar-stirrups-and-steel-stuff.html" target="_blank"&gt;Resources, Rotated Rebar Stirrups and Steel Stuff&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first links to a blog post by Aaron Lu. That and the other article explain the details of using the method and provide several examples of doing so. I hope that helps you further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 10:23:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11653794#M14773</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-01-03T10:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11657102#M14774</link>
      <description>&lt;P&gt;Is the column Slanted? The cast on line 31 will return null for slanted columns, causing an error on line 32. Can you find which line the error is on?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 16:39:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11657102#M14774</guid>
      <dc:creator>mhannonQ65N2</dc:creator>
      <dc:date>2023-01-04T16:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11658707#M14775</link>
      <description>&lt;P&gt;In my case, I didn't find any problem in selection, but the source of the problem is the variable RT (RebarBarType).&lt;/P&gt;&lt;P&gt;Till today, i can't locate the problem exactly !&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 09:23:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11658707#M14775</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-01-05T09:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11658934#M14776</link>
      <description>&lt;P&gt;Can you step through and debug?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 11:56:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/11658934#M14776</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-01-05T11:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rebar selected column</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/13770661#M84461</link>
      <description>&lt;P&gt;You can get RebarType by using LINQ&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var mainBarType = new FilteredElementCollector(doc)
                .OfClass(typeof(RebarBarType)).Cast&amp;lt;RebarBarType&amp;gt;()
                .FirstOrDefault(bt =&amp;gt; bt.Name == "32M");&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;refer video create Rebar of Column:&lt;BR /&gt;&lt;A href="https://youtu.be/Sxdq36EreA4?si=I_m2fuN7-qxTjqI_" target="_blank"&gt;https://youtu.be/Sxdq36EreA4?si=I_m2fuN7-qxTjqI_&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Aug 2025 10:15:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/rebar-selected-column/m-p/13770661#M84461</guid>
      <dc:creator>manhgt214</dc:creator>
      <dc:date>2025-08-17T10:15:39Z</dc:date>
    </item>
  </channel>
</rss>

