<?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: Create dimension line for rebar in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8234004#M48119</link>
    <description>&lt;P&gt;I use similar code&amp;nbsp;and verified with your plan A, there is an exception saying "The direction of dimension is invalid", the reason is the input value "dimension" should be inside the plan of doc.ActiveView. So I changed the input value dimension of the following code line to&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;line1.GeometryCurve &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; Line&lt;/U&gt;,&lt;/STRONG&gt;&amp;nbsp;it works, but you just need to offset Z of the &lt;STRONG&gt;dimension&lt;/STRONG&gt;&amp;nbsp;line to make it looks good.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dimension dim = doc.Create.NewDimension(doc.ActiveView, &lt;STRIKE&gt;dimension&lt;/STRIKE&gt; line1.GeometryCurve&amp;nbsp;&lt;SPAN class="s1"&gt;as&lt;/SPAN&gt;&amp;nbsp;Line, ra);
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Let me know if it works for you.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 22:23:30 GMT</pubDate>
    <dc:creator>zhong_wu</dc:creator>
    <dc:date>2018-08-29T22:23:30Z</dc:date>
    <item>
      <title>Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217536#M48114</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling to create a rebar dimension line because I can't find a way to get the&amp;nbsp;edges of the element in a Section View (see picture below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 110px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/537721i3ABF7033FA238174/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I could get the edge through their geometry, but this object (edge) doesn't have a "reference" to call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have some suggestions here? Any tip of advice will be well received.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 18:32:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217536#M48114</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-22T18:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217681#M48115</link>
      <description>&lt;P&gt;PS: I'm trying to create a dimension line to get the following situation. to measure how far is the end of the bar from a level/grid.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 362px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/537740iC1200927B8849B95/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:23:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217681#M48115</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-22T19:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217766#M48116</link>
      <description>&lt;P&gt;I had the same problem...still have it. Any help, or walk around, would be great!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:51:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8217766#M48116</guid>
      <dc:creator>lloyolaRLE</dc:creator>
      <dc:date>2018-08-22T19:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8218661#M48117</link>
      <description>&lt;P&gt;Hi Jorge,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just searched from the forum, and I found the similar question and&amp;nbsp;solution as follow:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read the geometry data from the rebar by Rebar.Geometry property. This property requires an Option argument. you need to set the option.ComputeReferences to true.&amp;nbsp;Then read the edge of the rebar, and get the curve from the Edge object. Finally get the end point reference from the curve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The original discussions can be found at:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/revit-api-forum/dimension-rebars/td-p/5356233" target="_blank"&gt;https://forums.autodesk.com/t5/revit-api-forum/dimension-rebars/td-p/5356233&lt;/A&gt; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/revit-api-forum/create-aligned-dimension-between-rebars/m-p/7083248/highlight/false#M22827" target="_blank"&gt;https://forums.autodesk.com/t5/revit-api-forum/create-aligned-dimension-between-rebars/m-p/7083248/highlight/false#M22827&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps;)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 08:02:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8218661#M48117</guid>
      <dc:creator>zhong_wu</dc:creator>
      <dc:date>2018-08-23T08:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8219218#M48118</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1240775"&gt;@zhong_wu&lt;/a&gt;, thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already looked at these posts but with no results. When I create the dimension line, a reference is needed. Using: "&lt;SPAN&gt;Then read the edge of the rebar and get the curve from the Edge object. Finally get the end point reference from the curve", when getting a reference from the edge I get "Null".&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here are 4 different paths&amp;nbsp;I took with no desired result:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;##### PLAN A #####

ReferenceArray ra = new ReferenceArray();
Line dimension = Line.CreateBound(rebar_top, apoyo_top);
DetailLine line1 = doc.Create.NewDetailCurve(view, dimension) as DetailLine;
ra.Append(line1.GeometryCurve.GetEndPointReference(1));
ra.Append(line1.GeometryCurve.GetEndPointReference(0));                                           
Dimension dim = doc.Create.NewDimension(doc.ActiveView, dimension, ra);


##### PLAN B #####

XYZ apoyo_top = pAnalisisSupCap + rle.cm_to_ft(200) * XYZ.BasisZ;
XYZ apoyo_bot = pAnalisisSupCap - rle.cm_to_ft(200) * XYZ.BasisZ;
XYZ rebar_top = pini + rle.cm_to_ft(200) * XYZ.BasisZ;
XYZ rebar_bot = pini - rle.cm_to_ft(200) * XYZ.BasisZ;
Line l_v = Line.CreateBound(apoyo_bot, apoyo_top);
Line l_h = Line.CreateBound(rebar_bot, rebar_top);

//SketchPlane skplane = SketchPlane.Create(doc, plano_vista);
Plane p_h = Plane.CreateByNormalAndOrigin(rebar_bot.CrossProduct(rebar_top), rebar_top);

//Plane p_h = Plane.CreateByNormalAndOrigin();
SketchPlane skplane_h = SketchPlane.Create(doc, p_h);

Plane p_v = Plane.CreateByNormalAndOrigin(apoyo_bot.CrossProduct(apoyo_top), apoyo_top);
SketchPlane skplane_v = SketchPlane.Create(doc, p_v);

ModelCurve modelcurve1 = doc.Create.NewModelCurve (l_h, skplane_h);
ModelCurve modelcurve2 = doc.Create.NewModelCurve(l_v, skplane_v);
 
ra.Append(modelcurve1.GeometryCurve.Reference);
ra.Append(modelcurve2.GeometryCurve.Reference);
ra.Append(modelcurve1.GeometryCurve.GetEndPointReference(0));
ra.Append(modelcurve2.GeometryCurve.GetEndPointReference(0));
											
##### PLAN C ##### 

Options opt = new Options();
opt.ComputeReferences = true;
opt.View = doc.ActiveView;
opt.IncludeNonVisibleObjects = true;
//opt.DetailLevel = ViewDetailLevel.Fine;

//GeometryElement geomElem = nvrant.getElemento().get_Geometry(opt); // VIGA entrega faces
GeometryElement geomElem = rebInt.get_Geometry(opt);
//GeometryElement geomElem = rebInt.GetFullGeometryForView(doc.ActiveView);
											
foreach (GeometryObject geomObj in geomElem)

{
	Solid geomSolid = geomObj as Solid;
	

	if (null != geomSolid)
	{
		int faces = 0;
		double totalArea = 0;
		foreach (Face geomFace in geomSolid.Faces)
		{
			faces++;
			faceInfo += "Face " + faces + " area: " + geomFace.Area.ToString() + "\n";
			totalArea += geomFace.Area;
			info = geomFace;
		}
		faceInfo += "Number of faces: " + faces + "\n";
		faceInfo += "Total area: " + totalArea.ToString() + "\n";

		int edge = 0;
		foreach (Edge geomEdge in geomSolid.Edges)
		{
			// get wall's geometry edges
			//if (edge == 0)
		   // {
				geoobj = geomEdge.AsCurve();
			// }
			// edge++;
			// faceInfo += "Edge " + edge +  "\n";

			
		   // Reference r1 = geoobj.GetEndPointReference(1);
		   // shapeHandlePoints.
		}
	}
}
// No Faces/Edges valiuds as references.
											
##### PLAN D ##### 
IList&amp;lt;RebarConstrainedHandle&amp;gt; dd = rebInt.GetRebarConstraintsManager().GetAllHandles();

RebarConstrainedHandle s = null;
RebarConstrainedHandle e = null;
foreach (RebarConstrainedHandle rbh in dd)
{
	if (rbh.GetHandleName().ToString() == "Start of Bar")
	{
		s = rbh;
	}
	if (rbh.GetHandleName().ToString() == "End of Bar")
	{
		e = rbh;
	}
}
// This objects (handles) doesn't give references.&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;What am I missing here?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 12:14:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8219218#M48118</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-23T12:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8234004#M48119</link>
      <description>&lt;P&gt;I use similar code&amp;nbsp;and verified with your plan A, there is an exception saying "The direction of dimension is invalid", the reason is the input value "dimension" should be inside the plan of doc.ActiveView. So I changed the input value dimension of the following code line to&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;line1.GeometryCurve &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; Line&lt;/U&gt;,&lt;/STRONG&gt;&amp;nbsp;it works, but you just need to offset Z of the &lt;STRONG&gt;dimension&lt;/STRONG&gt;&amp;nbsp;line to make it looks good.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dimension dim = doc.Create.NewDimension(doc.ActiveView, &lt;STRIKE&gt;dimension&lt;/STRIKE&gt; line1.GeometryCurve&amp;nbsp;&lt;SPAN class="s1"&gt;as&lt;/SPAN&gt;&amp;nbsp;Line, ra);
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Let me know if it works for you.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 22:23:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8234004#M48119</guid>
      <dc:creator>zhong_wu</dc:creator>
      <dc:date>2018-08-29T22:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8261797#M48120</link>
      <description>&lt;P&gt;With the great support&amp;nbsp;from our Revit engineer, I got the solution and verified, it works fine to dimension between rebar and grid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;contains a command that place a dimension in your model. You will need to select the rebar. The grid line is hard-coded by id.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;It implemented the following idea: Get all rebar references and filter them (choose the only one that we need). Get the grid reference. With the rebar ref and grid ref create the dimension.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to only dimension the rebar, you just need to change the code to get the 2 reference&amp;nbsp;of edges which&amp;nbsp;are&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;perpendicular with&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;EM&gt;rebarSeg&lt;/EM&gt;, hope it helps:&lt;/P&gt;
&lt;PRE&gt;using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure;

namespace TestRebar
{
   [TransactionAttribute(TransactionMode.Manual)]
   [RegenerationAttribute(RegenerationOption.Manual)]
   public class TestRebar : IExternalCommand
   {
      UIApplication m_uiApp;
      Document m_doc;

      ElementId elementId = ElementId.InvalidElementId;

      public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
      {
         try
         {
            initStuff(commandData);
            if (m_doc == null)
               return Result.Failed;

            m_uiApp = commandData.Application;
            Selection sel = m_uiApp.ActiveUIDocument.Selection;
            Reference refr = sel.PickObject(ObjectType.Element);
          
            Rebar rebar = m_doc.GetElement(refr.ElementId) as Rebar;

            Line rebarSeg = null;
            bool bOk = getRebarSegment(rebar, out rebarSeg);
            if (!bOk)
               return Result.Failed;

            Options options = new Options();
            options.View = m_uiApp.ActiveUIDocument.ActiveView; // the view in which you want to place the dimension
            options.ComputeReferences = true; // This will produce the references
            options.IncludeNonVisibleObjects = true;
            GeometryElement wholeRebarGeometry = rebar.get_Geometry(options);
            Reference refForEndOfBar = getReferenceForEndOfBar(wholeRebarGeometry, rebarSeg);


            Reference refGrid = getGridRef();

            ReferenceArray refArray = new ReferenceArray();
            refArray.Append(refForEndOfBar);
            refArray.Append(refGrid);

            double dist = 10;

            Line dimLine = rebarSeg.CreateOffset(dist, XYZ.BasisY) as Line; // a line parallel with our rebar segment somewhere in the space.

            using (Transaction tr = new Transaction(m_doc, "Create Dimension"))
            {
               tr.Start();
               m_doc.Create.NewDimension(m_uiApp.ActiveUIDocument.ActiveView, dimLine, refArray);
               tr.Commit();
            }
         }
         catch (Exception e)
         {
            TaskDialog.Show("exception", e.Message);
            return Result.Failed;
         }

         return Result.Succeeded;
      }

      private Reference getGridRef()
      {
         ElementId idGrd = new ElementId(397028);
         Element elemGrid = m_doc.GetElement(idGrd);
         Options options = new Options();
         options.View = m_uiApp.ActiveUIDocument.ActiveView; // the view in which you want to place the dimension
         options.ComputeReferences = true; // This will produce the references
         options.IncludeNonVisibleObjects = true;
         GeometryElement wholeGridGeometry = elemGrid.get_Geometry(options);
         IList&amp;lt;Reference&amp;gt; allRefs = new List&amp;lt;Reference&amp;gt;();
         foreach (GeometryObject geomObj in wholeGridGeometry)
         {
            Line refLine = geomObj as Line;
            if (refLine != null &amp;amp;&amp;amp; refLine.Reference != null)
               return refLine.Reference;
         }

         return null; 
      }

      private Reference getReferenceForEndOfBar(GeometryElement geom, Line rebarSeg)
      {
         foreach (GeometryObject geomObj in geom)
         {
            Solid sld = geomObj as Solid;
            if (sld != null)
            {
               // I'll get the references from curves;
               continue;
            }
            else
            {
               Line refLine = geomObj as Line;
               if (refLine != null &amp;amp;&amp;amp; refLine.Reference !=null)
               {
                  // We found one reference. Let's see if it is the correct one. 
                  // The correct referece need to be perpendicular to rebar segement and the end point of rebar segment should be on the reference curve.
                  double dotProd = refLine.Direction.DotProduct(rebarSeg.Direction);
                  if (Math.Abs(dotProd) != 0) 
                     continue; // curves are not perpendicular.

                  XYZ endPointOfRebar = rebarSeg.GetEndPoint(1);
                  IntersectionResult ir = refLine.Project(endPointOfRebar);
                  if (ir == null)
                     continue; // end point of rebar segment is not on the reference curve.

                  if (Math.Abs(ir.Distance) != 0)
                     continue; // end point of rebar segment is not on the reference curve.

                  return refLine.Reference;
               }
            }
         }
         return null;
      }

      private bool getRebarSegment(Rebar rebar, out Line rebarSeg)
      {
         rebarSeg = null;
         IList&amp;lt;Curve&amp;gt; rebarSegments = rebar.GetCenterlineCurves(false, true, true, MultiplanarOption.IncludeOnlyPlanarCurves, 0);
         if (rebarSegments.Count != 1)
            return false;

         rebarSeg = rebarSegments[0] as Line;
         if (rebarSeg == null)
            return false;

         return true;
      }

      void initStuff(ExternalCommandData commandData)
      {
         m_uiApp = commandData.Application;
         m_doc = m_uiApp.ActiveUIDocument.Document;
      }
   }
}




&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 03:54:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8261797#M48120</guid>
      <dc:creator>zhong_wu</dc:creator>
      <dc:date>2018-09-12T03:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create dimension line for rebar</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8263088#M48121</link>
      <description>&lt;P&gt;Dear Zhon Wu,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for the response. It is the solution to our problem! We made little adjustments to the code to have plenty of control about what end do we want to dimension and also we had to project all the curves involved in a shared reference plane due that if you have more than one rebar (rebar set) the geometry of the rebar is above or beneath the grid line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thanks a lot for your time and effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 14:15:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-line-for-rebar/m-p/8263088#M48121</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-09-12T14:15:08Z</dc:date>
    </item>
  </channel>
</rss>

