<?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 Dimension subelement not working in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10224509#M26752</link>
    <description>&lt;P&gt;[Revit API , CSharp]&lt;/P&gt;&lt;P&gt;Hi everyone, I hope you will help me!!&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#endregion

namespace Question
{

    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {


        public Document doc { get; set; }
        /// &amp;lt;summary&amp;gt;
        /// External command mainline
        /// &amp;lt;/summary&amp;gt;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Display WPF Form
                // _wpfWindowController.ShowForm(commandData.Application);
                doc = commandData.Application.ActiveUIDocument.Document;
                DimensionType dimensionType = new FilteredElementCollector(doc).OfClass(typeof(DimensionType)).Cast&amp;lt;DimensionType&amp;gt;().FirstOrDefault();

                Grid gridperH = doc.GetElement(new ElementId(419358)) as Grid;
                FamilyInstance ins = doc.GetElement(new ElementId(419291)) as FamilyInstance;
                XYZ loc = (ins.Location as LocationPoint).Point;
                Line line = Line.CreateBound(loc + XYZ.BasisY, loc + XYZ.BasisY + XYZ.BasisX);
                // Dimension OK
                FamilyInstance insSingle = doc.GetElement(new ElementId(422010)) as FamilyInstance;
                ReferenceArray referenceArr = new ReferenceArray();
                referenceArr.Append(GetReferenceFromGrid(gridperH));
                referenceArr.Append(GetCurveCenterFamilyInstance(insSingle));
                DimensionTest(line, referenceArr);
                // Dimension Sub Element : Error
                referenceArr = new ReferenceArray();
                referenceArr.Append(GetReferenceFromGrid(gridperH));
                referenceArr.Append(GetCurveCenterFamilyInstance(ins));
                DimensionTest(line, referenceArr);
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
        public void DimensionTest(Line line, ReferenceArray refArr)
        {
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start(" TransactionName ");
                doc.Create.NewDimension(doc.ActiveView, line, refArr);
                tx.Commit();
            }
        }
        public Reference GetReferenceFromGrid(Grid grid)
        {
            Reference reference = null;
            Options DefaultOptions = new Options();
            DefaultOptions.ComputeReferences = true;
            DefaultOptions.IncludeNonVisibleObjects = true;
            DefaultOptions.View = doc.ActiveView;
            GeometryElement geoElem = grid.get_Geometry(DefaultOptions);
            double length = 0;
            foreach (var item in geoElem)
            {
                Curve curve = item as Curve;
                if (curve != null)
                {
                    if (curve.Length &amp;gt; length)
                    {
                        reference = curve.Reference;
                        length = curve.Length;
                    }
                }
            }
            return reference;
        }
        public Reference GetCurveCenterFamilyInstance(FamilyInstance faIns)
        {
            Options geomOptions = new Options();
            geomOptions.ComputeReferences = true;
            geomOptions.View = doc.ActiveView;
            geomOptions.IncludeNonVisibleObjects = true;
            GeometryElement gElement = faIns.get_Geometry(geomOptions);
            List&amp;lt;Curve&amp;gt; lstcu = GetCurvesElement(gElement, false);
            var curveOrigin = lstcu.Where(k =&amp;gt; k.IsBound == true &amp;amp;&amp;amp; (k as Line) != null &amp;amp;&amp;amp;
            (k.GetEndPoint(0).DistanceTo(new XYZ(0, 0, k.GetEndPoint(0).Z)) &amp;lt;= 0.0001 || k.GetEndPoint(1).DistanceTo(new XYZ(0, 0, k.GetEndPoint(1).Z)) &amp;lt;= 0.0001))
                .FirstOrDefault();
            return (curveOrigin.GetEndPoint(0).DistanceTo(XYZ.Zero) &amp;lt; curveOrigin.GetEndPoint(1).DistanceTo(XYZ.Zero)) ? curveOrigin.GetEndPointReference(0) : curveOrigin.GetEndPointReference(1);
        }
        public List&amp;lt;Curve&amp;gt; GetCurvesElement(GeometryElement geoEle, bool IsGetGeometryInstance = true)
        {
            List&amp;lt;Curve&amp;gt; lstcuves = GetCurvesGeoElement(geoEle, IsGetGeometryInstance);
            return lstcuves;
        }
        private List&amp;lt;Curve&amp;gt; GetCurvesGeoElement(GeometryElement geoEle, bool IsGetGeometryInstance = true)
        {
            List&amp;lt;Curve&amp;gt; lstRes = new List&amp;lt;Curve&amp;gt;();
            // get references
            foreach (var geo in geoEle)
            {
                GeometryInstance geoIns = geo as GeometryInstance;
                if (geoIns != null)
                {
                    GeometryElement newGeo = IsGetGeometryInstance == true ? geoIns.GetInstanceGeometry() : geoIns.GetSymbolGeometry();
                    if (newGeo != null)
                    {
                        List&amp;lt;Curve&amp;gt; lst = GetCurvesGeoElement(newGeo, IsGetGeometryInstance);
                        if (lst.Count &amp;gt; 0)
                        {
                            lstRes.AddRange(lst);
                        }
                    }
                }
                Curve curve = geo as Curve;
                if (curve != null)
                {
                    lstRes.Add(curve);
                }
            }
            return lstRes;
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;My problem is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;- (id=422101): If I dim the familyInstance object, it runs normally&lt;BR /&gt;- (id=419291): But since I dim familyInstance is a sub element&amp;nbsp; then it doesn't work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;------&amp;nbsp; &amp;nbsp;family (419291) = Family (422010)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="question2.png" style="width: 742px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/904263iDCB68B67133E402B/image-size/large?v=v2&amp;amp;px=999" role="button" title="question2.png" alt="question2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My code + File Revit:&amp;nbsp;&lt;A href="https://drive.google.com/drive/folders/1T4-v_WcTcc-8KW3W9CYkU9f6iPdgrcUr?usp=sharing" target="_blank"&gt;https://drive.google.com/drive/folders/1T4-v_WcTcc-8KW3W9CYkU9f6iPdgrcUr?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[If there are examples, the better!!]&lt;/P&gt;&lt;P&gt;Thanks you very much!!!&lt;/P&gt;</description>
    <pubDate>Fri, 09 Apr 2021 10:24:09 GMT</pubDate>
    <dc:creator>dreamofbaby0507</dc:creator>
    <dc:date>2021-04-09T10:24:09Z</dc:date>
    <item>
      <title>Dimension subelement not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10224509#M26752</link>
      <description>&lt;P&gt;[Revit API , CSharp]&lt;/P&gt;&lt;P&gt;Hi everyone, I hope you will help me!!&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#endregion

namespace Question
{

    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {


        public Document doc { get; set; }
        /// &amp;lt;summary&amp;gt;
        /// External command mainline
        /// &amp;lt;/summary&amp;gt;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Display WPF Form
                // _wpfWindowController.ShowForm(commandData.Application);
                doc = commandData.Application.ActiveUIDocument.Document;
                DimensionType dimensionType = new FilteredElementCollector(doc).OfClass(typeof(DimensionType)).Cast&amp;lt;DimensionType&amp;gt;().FirstOrDefault();

                Grid gridperH = doc.GetElement(new ElementId(419358)) as Grid;
                FamilyInstance ins = doc.GetElement(new ElementId(419291)) as FamilyInstance;
                XYZ loc = (ins.Location as LocationPoint).Point;
                Line line = Line.CreateBound(loc + XYZ.BasisY, loc + XYZ.BasisY + XYZ.BasisX);
                // Dimension OK
                FamilyInstance insSingle = doc.GetElement(new ElementId(422010)) as FamilyInstance;
                ReferenceArray referenceArr = new ReferenceArray();
                referenceArr.Append(GetReferenceFromGrid(gridperH));
                referenceArr.Append(GetCurveCenterFamilyInstance(insSingle));
                DimensionTest(line, referenceArr);
                // Dimension Sub Element : Error
                referenceArr = new ReferenceArray();
                referenceArr.Append(GetReferenceFromGrid(gridperH));
                referenceArr.Append(GetCurveCenterFamilyInstance(ins));
                DimensionTest(line, referenceArr);
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
        public void DimensionTest(Line line, ReferenceArray refArr)
        {
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start(" TransactionName ");
                doc.Create.NewDimension(doc.ActiveView, line, refArr);
                tx.Commit();
            }
        }
        public Reference GetReferenceFromGrid(Grid grid)
        {
            Reference reference = null;
            Options DefaultOptions = new Options();
            DefaultOptions.ComputeReferences = true;
            DefaultOptions.IncludeNonVisibleObjects = true;
            DefaultOptions.View = doc.ActiveView;
            GeometryElement geoElem = grid.get_Geometry(DefaultOptions);
            double length = 0;
            foreach (var item in geoElem)
            {
                Curve curve = item as Curve;
                if (curve != null)
                {
                    if (curve.Length &amp;gt; length)
                    {
                        reference = curve.Reference;
                        length = curve.Length;
                    }
                }
            }
            return reference;
        }
        public Reference GetCurveCenterFamilyInstance(FamilyInstance faIns)
        {
            Options geomOptions = new Options();
            geomOptions.ComputeReferences = true;
            geomOptions.View = doc.ActiveView;
            geomOptions.IncludeNonVisibleObjects = true;
            GeometryElement gElement = faIns.get_Geometry(geomOptions);
            List&amp;lt;Curve&amp;gt; lstcu = GetCurvesElement(gElement, false);
            var curveOrigin = lstcu.Where(k =&amp;gt; k.IsBound == true &amp;amp;&amp;amp; (k as Line) != null &amp;amp;&amp;amp;
            (k.GetEndPoint(0).DistanceTo(new XYZ(0, 0, k.GetEndPoint(0).Z)) &amp;lt;= 0.0001 || k.GetEndPoint(1).DistanceTo(new XYZ(0, 0, k.GetEndPoint(1).Z)) &amp;lt;= 0.0001))
                .FirstOrDefault();
            return (curveOrigin.GetEndPoint(0).DistanceTo(XYZ.Zero) &amp;lt; curveOrigin.GetEndPoint(1).DistanceTo(XYZ.Zero)) ? curveOrigin.GetEndPointReference(0) : curveOrigin.GetEndPointReference(1);
        }
        public List&amp;lt;Curve&amp;gt; GetCurvesElement(GeometryElement geoEle, bool IsGetGeometryInstance = true)
        {
            List&amp;lt;Curve&amp;gt; lstcuves = GetCurvesGeoElement(geoEle, IsGetGeometryInstance);
            return lstcuves;
        }
        private List&amp;lt;Curve&amp;gt; GetCurvesGeoElement(GeometryElement geoEle, bool IsGetGeometryInstance = true)
        {
            List&amp;lt;Curve&amp;gt; lstRes = new List&amp;lt;Curve&amp;gt;();
            // get references
            foreach (var geo in geoEle)
            {
                GeometryInstance geoIns = geo as GeometryInstance;
                if (geoIns != null)
                {
                    GeometryElement newGeo = IsGetGeometryInstance == true ? geoIns.GetInstanceGeometry() : geoIns.GetSymbolGeometry();
                    if (newGeo != null)
                    {
                        List&amp;lt;Curve&amp;gt; lst = GetCurvesGeoElement(newGeo, IsGetGeometryInstance);
                        if (lst.Count &amp;gt; 0)
                        {
                            lstRes.AddRange(lst);
                        }
                    }
                }
                Curve curve = geo as Curve;
                if (curve != null)
                {
                    lstRes.Add(curve);
                }
            }
            return lstRes;
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;My problem is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;- (id=422101): If I dim the familyInstance object, it runs normally&lt;BR /&gt;- (id=419291): But since I dim familyInstance is a sub element&amp;nbsp; then it doesn't work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;------&amp;nbsp; &amp;nbsp;family (419291) = Family (422010)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="question2.png" style="width: 742px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/904263iDCB68B67133E402B/image-size/large?v=v2&amp;amp;px=999" role="button" title="question2.png" alt="question2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My code + File Revit:&amp;nbsp;&lt;A href="https://drive.google.com/drive/folders/1T4-v_WcTcc-8KW3W9CYkU9f6iPdgrcUr?usp=sharing" target="_blank"&gt;https://drive.google.com/drive/folders/1T4-v_WcTcc-8KW3W9CYkU9f6iPdgrcUr?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[If there are examples, the better!!]&lt;/P&gt;&lt;P&gt;Thanks you very much!!!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 10:24:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10224509#M26752</guid>
      <dc:creator>dreamofbaby0507</dc:creator>
      <dc:date>2021-04-09T10:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dimension subelement not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10225132#M26753</link>
      <description>&lt;P&gt;You are trying the place dimensions. Dimensions only work on visible objects. The dimension you created is in the database, but isn't shown because it refers to a non-visible line.&lt;/P&gt;&lt;P&gt;Set the value for [&amp;nbsp;geomOptions.IncludeNonVisibleObjects ] to false in the&amp;nbsp; &lt;SPAN&gt;GetCurveCenterFamilyInstance() method, and all should be fine.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 14:13:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10225132#M26753</guid>
      <dc:creator>FAIR59</dc:creator>
      <dc:date>2021-04-09T14:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dimension subelement not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10225211#M26754</link>
      <description>&lt;P&gt;I have done it. Thank you very much!!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 14:38:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/dimension-subelement-not-working/m-p/10225211#M26754</guid>
      <dc:creator>dreamofbaby0507</dc:creator>
      <dc:date>2021-04-09T14:38:19Z</dc:date>
    </item>
  </channel>
</rss>

