<?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 Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272714#M1365</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am working on a project where I need to add dimensions to an edge in an assembly view. The dimensions are generated using Revit API code, and everything seems to work fine initially. However, when I manually move the dimension in the view, the dimension value changes to zero, which is not the desired behavior.&lt;/P&gt;&lt;P&gt;Issue:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension is placed on the edge of an object in an assembly view.(image Before)&lt;/LI&gt;&lt;LI&gt;When I move the dimension manually in the view, it changes to zero, even though the geometry and edge position remain unchanged.(image After)&lt;/LI&gt;&lt;LI&gt;The goal is to prevent the dimension value from changing when the dimension is moved in the view.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;What I've Tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension is generated using Revit API code and is initially set correctly.&lt;/LI&gt;&lt;LI&gt;I've confirmed that the view is an assembly view.&lt;/LI&gt;&lt;LI&gt;When moving the dimension manually, the dimension value becomes zero.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Desired Behavior:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension should remain consistent, and its value should not change when moved.&lt;/LI&gt;&lt;LI&gt;The value should reflect the correct measurement between the two reference points, even if the dimension line is manually adjusted in the view.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I would appreciate any advice or suggestions on how to handle this issue programmatically to ensure that the dimension value remains fixed even when moved manually.&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Windows;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace MGL.Core.Create.ShopDrawing
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ShopdrawingDimension_Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                UIApplication uiapp = commandData.Application;
                UIDocument uiDoc = uiapp.ActiveUIDocument;
                Document doc = uiDoc.Document;

                // Step 1: Select a viewport from the sheet
                Viewport viewport = SelectViewport(uiDoc);
                if (viewport == null)
                {
                    TaskDialog.Show("Cancelled", "No viewport selected.");
                    return Result.Cancelled;
                }

                // Step 2: Get the view associated with the selected viewport
                View view = doc.GetElement(viewport.ViewId) as View;
                if (view == null)
                {
                    TaskDialog.Show("Error", "The selected viewport does not have a valid view.");
                    return Result.Failed;
                }

                // Step 3: Get the visible walls in the view
                var wallsInView = GetWallsInView(doc, view);
                if (!wallsInView.Any())
                {
                    TaskDialog.Show("No Walls", "No walls found in the selected view.");
                    return Result.Cancelled;
                }

                using (Transaction tx = new Transaction(doc, "Add Dimensions to Slanted Walls"))
                {
                    tx.Start();

                    foreach (var wall in wallsInView)
                    {
                        // Add dimensions to each wall in the view
                        AddDimensionsToWall(doc, view, wall);
                    }

                    tx.Commit();
                }

                TaskDialog.Show("Success", "Dimensions added to the selected walls.");
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Execution Failed", $"Error: {ex.Message}");
                message = ex.Message;
                return Result.Failed;
            }
        }


        private Viewport SelectViewport(UIDocument uiDoc)
        {
            try
            {
                // Select a viewport from the sheet
                Reference reference = uiDoc.Selection.PickObject(ObjectType.Element, new ViewportSelectionFilter(), "Select a viewport from the sheet");
                Element element = uiDoc.Document.GetElement(reference);
                return element as Viewport;
            }
            catch
            {
                return null;
            }
        }

        private List&amp;lt;Wall&amp;gt; GetWallsInView(Document doc, View view)
        {
            // Get walls visible in the selected view
            return new FilteredElementCollector(doc, view.Id)
                .OfClass(typeof(Wall))
                .Cast&amp;lt;Wall&amp;gt;()
                .ToList();
        }

        private bool IsFaceVisibleInView(PlanarFace face, View view)
        {
            // Check if the face is visible in the current view
            XYZ faceNormal = face.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // The face is visible if its normal is perpendicular to the view direction
            return Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;lt; 0.01;
        }





        private void AddDimensionsToWall(Document doc, View view, Wall wall)
        {
            // Get the geometry of the wall
            Options options = new Options
            {
                ComputeReferences = true,
                View = view
            };
            GeometryElement geometryElement = wall.get_Geometry(options);

            foreach (GeometryObject geometryObject in geometryElement)
            {
                if (geometryObject is Solid solid)
                {
                    // Iterate through the faces of the solid
                    foreach (Face face in solid.Faces)
                    {
                        if (face is PlanarFace originalFace)
                        {
                            // Apply the transformation to align the face normal with the view direction
                            PlanarFace alignedFace = AlignFaceWithView(originalFace, view);

                            // Check if the aligned face is visible in the view
                            if (IsFaceVisibleInView(alignedFace, view))
                            {
                                // Create dimensions for the aligned face
                                CreateDimensionsForFace(doc, view, alignedFace);
                            }
                        }
                    }
                }
            }
        }


        private Transform GetTransformationToAlignFaceWithView(PlanarFace face, View view)
        {
            XYZ faceNormal = face.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // If face normal is already aligned with the view direction, no transformation is needed
            if (Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;gt; 0.999)
                return null;

            // Create a rotation transformation to align the face normal with the view direction
            XYZ rotationAxis = faceNormal.CrossProduct(viewDirection).Normalize();
            double angle = faceNormal.AngleTo(viewDirection);

            // Create and return the transformation
            return Transform.CreateRotationAtPoint(rotationAxis, angle, face.Origin);
        }



        private PlanarFace AlignFaceWithView(PlanarFace originalFace, View view)
        {
            XYZ faceNormal = originalFace.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // If the face normal is already aligned with the view direction, return the original face
            if (Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;gt; 0.999)
                return originalFace;

            // Create a rotation transformation to align the face normal with the view direction
            XYZ rotationAxis = faceNormal.CrossProduct(viewDirection).Normalize();
            double angle = faceNormal.AngleTo(viewDirection);

            // Create the rotation transformation
            Transform rotationTransform = Transform.CreateRotationAtPoint(rotationAxis, angle, originalFace.Origin);

            // Apply the rotation to the face geometry (manually transform the geometry)
            foreach (Edge edge in originalFace.EdgeLoops.get_Item(0))
            {
                // Transform each edge of the face
                Curve curve = edge.AsCurve();
                curve = curve.CreateTransformed(rotationTransform);
            }

            // Return the transformed face
            return originalFace;
        }

        private void CreateDimensionsForFace(Document doc, View view, PlanarFace face)
        {
            // Get bounding edges of the face
            EdgeArray edges = face.EdgeLoops.get_Item(0);

            // Collect references for dimensioning
            ReferenceArray references = new ReferenceArray();
            List&amp;lt;XYZ&amp;gt; edgePoints = new List&amp;lt;XYZ&amp;gt;();

            foreach (Edge edge in edges)
            {
                Curve curve = edge.AsCurve();
                if (curve is Line line)
                {
                    // Add edge reference to the array
                    references.Append(edge.Reference);

                    // Add the endpoints of the line for dimensioning
                    edgePoints.Add(line.GetEndPoint(0));
                    edgePoints.Add(line.GetEndPoint(1));
                }
            }

            // Ensure at least two references for a valid dimension
            if (references.Size &amp;lt; 2 || edgePoints.Count &amp;lt; 2)
            {
                TaskDialog.Show("Error", "Not enough references to create a dimension.");
                return;
            }

            // Determine dimension line direction based on edge points
            XYZ dimensionStart = edgePoints.First();
            XYZ dimensionEnd = edgePoints.Last();

            // Calculate the direction between the points
            XYZ dimensionDirection = dimensionEnd - dimensionStart;

            // Debugging: Show dimension line information
            TaskDialog.Show("Dimension Info", $"Start: {dimensionStart}\nEnd: {dimensionEnd}\nDirection: {dimensionDirection}");

            // Ensure the direction is valid for dimensioning (avoid small magnitude)
            if (dimensionDirection.IsZeroLength())
            {
                TaskDialog.Show("Error", "The start and end points are identical, invalid dimension direction.");
                return;
            }

            // Define a minimum threshold for valid dimension size
            double minDimensionSize = 0.01;  // Example: 0.01 units as the threshold (can be adjusted)

            // Check if the dimension size is too small
            if (dimensionDirection.GetLength() &amp;lt; minDimensionSize)
            {
                TaskDialog.Show("Warning", "The dimension size is too small to be valid.");
                return; // Skip creating dimension for too small sizes
            }

            // Check that the direction vector is valid and non-zero
            if (dimensionDirection.IsZeroLength() || dimensionDirection.DotProduct(XYZ.BasisZ) &amp;lt; 0.001)
            {
                TaskDialog.Show("Error", "The dimension direction is invalid. Please ensure the edge is valid for dimensioning.");
                return;
            }

            // Proceed with dimension creation
            Line dimensionLine = Line.CreateBound(dimensionStart, dimensionEnd);
            

            // Create the dimension using the line direction
            doc.Create.NewDimension(view, dimensionLine, references);
        }







        /// &amp;lt;summary&amp;gt;
        /// Check if a face normal aligns with the view's direction.
        /// &amp;lt;/summary&amp;gt;
        private bool IsAlignedWithView(View view, XYZ normal)
        {
            if (view is ViewPlan || view is ViewSection)
            {
                // Get the view direction
                XYZ viewDirection = view.ViewDirection.Normalize();

                // Calculate the dot product between the face normal and view direction
                double dotProduct = Math.Abs(viewDirection.DotProduct(normal));

                // Log values for debugging
                TaskDialog.Show("Debug Info", $"Face Normal: {normal}\nView Direction: {viewDirection}\nDot Product: {dotProduct}");

                // Allow more tolerance for alignment (e.g., 0.95 instead of 0.99)
                return dotProduct &amp;gt; 0.95; // More tolerance for face alignment
            }

            return true; // Assume alignment for other view types
        }




        /// &amp;lt;summary&amp;gt;
        /// Check if a line lies in the plane of the view.
        /// &amp;lt;/summary&amp;gt;
        private bool IsLineInViewPlane(View view, Line line)
        {
            // Get the plane of the view
            Plane viewPlane = view.SketchPlane?.GetPlane();
            if (viewPlane == null) return false;

            // Validate each endpoint of the line
            return IsPointOnPlane(viewPlane, line.GetEndPoint(0)) &amp;amp;&amp;amp; IsPointOnPlane(viewPlane, line.GetEndPoint(1));
        }

        /// &amp;lt;summary&amp;gt;
        /// Verify if the face normal aligns with the view direction.
        /// &amp;lt;/summary&amp;gt;
        private bool IsFaceNormalAlignedWithView(View view, PlanarFace face)
        {
            // Get the view's direction
            XYZ viewDirection = view.ViewDirection.Normalize();

            // Get the face's normal
            XYZ faceNormal = face.FaceNormal.Normalize();

            // Check alignment (parallel or antiparallel)
            double dotProduct = faceNormal.DotProduct(viewDirection);

            // Allow small tolerance for floating-point comparison
            return Math.Abs(dotProduct) &amp;gt; 0.999; // 0.999 allows for minimal deviation
        }


        /// &amp;lt;summary&amp;gt;
        /// Check if a point lies on a given plane.
        /// &amp;lt;/summary&amp;gt;
        private bool IsPointOnPlane(Plane plane, XYZ point)
        {
            // Vector from the plane's origin to the point
            XYZ vector = point - plane.Origin;

            // Check if the vector is perpendicular to the plane's normal
            return Math.Abs(plane.Normal.DotProduct(vector)) &amp;lt; 1e-6; // Tolerance for floating-point comparison
        }



        private class ViewportSelectionFilter : ISelectionFilter
        {
            public bool AllowElement(Element element) =&amp;gt; element is Viewport;
            public bool AllowReference(Reference reference, XYZ position) =&amp;gt; false;
        }
       

        
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jan 2025 04:14:12 GMT</pubDate>
    <dc:creator>DesignGroup01</dc:creator>
    <dc:date>2025-01-21T04:14:12Z</dc:date>
    <item>
      <title>Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272714#M1365</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am working on a project where I need to add dimensions to an edge in an assembly view. The dimensions are generated using Revit API code, and everything seems to work fine initially. However, when I manually move the dimension in the view, the dimension value changes to zero, which is not the desired behavior.&lt;/P&gt;&lt;P&gt;Issue:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension is placed on the edge of an object in an assembly view.(image Before)&lt;/LI&gt;&lt;LI&gt;When I move the dimension manually in the view, it changes to zero, even though the geometry and edge position remain unchanged.(image After)&lt;/LI&gt;&lt;LI&gt;The goal is to prevent the dimension value from changing when the dimension is moved in the view.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;What I've Tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension is generated using Revit API code and is initially set correctly.&lt;/LI&gt;&lt;LI&gt;I've confirmed that the view is an assembly view.&lt;/LI&gt;&lt;LI&gt;When moving the dimension manually, the dimension value becomes zero.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Desired Behavior:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The dimension should remain consistent, and its value should not change when moved.&lt;/LI&gt;&lt;LI&gt;The value should reflect the correct measurement between the two reference points, even if the dimension line is manually adjusted in the view.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I would appreciate any advice or suggestions on how to handle this issue programmatically to ensure that the dimension value remains fixed even when moved manually.&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Windows;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace MGL.Core.Create.ShopDrawing
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ShopdrawingDimension_Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                UIApplication uiapp = commandData.Application;
                UIDocument uiDoc = uiapp.ActiveUIDocument;
                Document doc = uiDoc.Document;

                // Step 1: Select a viewport from the sheet
                Viewport viewport = SelectViewport(uiDoc);
                if (viewport == null)
                {
                    TaskDialog.Show("Cancelled", "No viewport selected.");
                    return Result.Cancelled;
                }

                // Step 2: Get the view associated with the selected viewport
                View view = doc.GetElement(viewport.ViewId) as View;
                if (view == null)
                {
                    TaskDialog.Show("Error", "The selected viewport does not have a valid view.");
                    return Result.Failed;
                }

                // Step 3: Get the visible walls in the view
                var wallsInView = GetWallsInView(doc, view);
                if (!wallsInView.Any())
                {
                    TaskDialog.Show("No Walls", "No walls found in the selected view.");
                    return Result.Cancelled;
                }

                using (Transaction tx = new Transaction(doc, "Add Dimensions to Slanted Walls"))
                {
                    tx.Start();

                    foreach (var wall in wallsInView)
                    {
                        // Add dimensions to each wall in the view
                        AddDimensionsToWall(doc, view, wall);
                    }

                    tx.Commit();
                }

                TaskDialog.Show("Success", "Dimensions added to the selected walls.");
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Execution Failed", $"Error: {ex.Message}");
                message = ex.Message;
                return Result.Failed;
            }
        }


        private Viewport SelectViewport(UIDocument uiDoc)
        {
            try
            {
                // Select a viewport from the sheet
                Reference reference = uiDoc.Selection.PickObject(ObjectType.Element, new ViewportSelectionFilter(), "Select a viewport from the sheet");
                Element element = uiDoc.Document.GetElement(reference);
                return element as Viewport;
            }
            catch
            {
                return null;
            }
        }

        private List&amp;lt;Wall&amp;gt; GetWallsInView(Document doc, View view)
        {
            // Get walls visible in the selected view
            return new FilteredElementCollector(doc, view.Id)
                .OfClass(typeof(Wall))
                .Cast&amp;lt;Wall&amp;gt;()
                .ToList();
        }

        private bool IsFaceVisibleInView(PlanarFace face, View view)
        {
            // Check if the face is visible in the current view
            XYZ faceNormal = face.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // The face is visible if its normal is perpendicular to the view direction
            return Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;lt; 0.01;
        }





        private void AddDimensionsToWall(Document doc, View view, Wall wall)
        {
            // Get the geometry of the wall
            Options options = new Options
            {
                ComputeReferences = true,
                View = view
            };
            GeometryElement geometryElement = wall.get_Geometry(options);

            foreach (GeometryObject geometryObject in geometryElement)
            {
                if (geometryObject is Solid solid)
                {
                    // Iterate through the faces of the solid
                    foreach (Face face in solid.Faces)
                    {
                        if (face is PlanarFace originalFace)
                        {
                            // Apply the transformation to align the face normal with the view direction
                            PlanarFace alignedFace = AlignFaceWithView(originalFace, view);

                            // Check if the aligned face is visible in the view
                            if (IsFaceVisibleInView(alignedFace, view))
                            {
                                // Create dimensions for the aligned face
                                CreateDimensionsForFace(doc, view, alignedFace);
                            }
                        }
                    }
                }
            }
        }


        private Transform GetTransformationToAlignFaceWithView(PlanarFace face, View view)
        {
            XYZ faceNormal = face.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // If face normal is already aligned with the view direction, no transformation is needed
            if (Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;gt; 0.999)
                return null;

            // Create a rotation transformation to align the face normal with the view direction
            XYZ rotationAxis = faceNormal.CrossProduct(viewDirection).Normalize();
            double angle = faceNormal.AngleTo(viewDirection);

            // Create and return the transformation
            return Transform.CreateRotationAtPoint(rotationAxis, angle, face.Origin);
        }



        private PlanarFace AlignFaceWithView(PlanarFace originalFace, View view)
        {
            XYZ faceNormal = originalFace.FaceNormal;
            XYZ viewDirection = view.ViewDirection.Normalize();

            // If the face normal is already aligned with the view direction, return the original face
            if (Math.Abs(faceNormal.DotProduct(viewDirection)) &amp;gt; 0.999)
                return originalFace;

            // Create a rotation transformation to align the face normal with the view direction
            XYZ rotationAxis = faceNormal.CrossProduct(viewDirection).Normalize();
            double angle = faceNormal.AngleTo(viewDirection);

            // Create the rotation transformation
            Transform rotationTransform = Transform.CreateRotationAtPoint(rotationAxis, angle, originalFace.Origin);

            // Apply the rotation to the face geometry (manually transform the geometry)
            foreach (Edge edge in originalFace.EdgeLoops.get_Item(0))
            {
                // Transform each edge of the face
                Curve curve = edge.AsCurve();
                curve = curve.CreateTransformed(rotationTransform);
            }

            // Return the transformed face
            return originalFace;
        }

        private void CreateDimensionsForFace(Document doc, View view, PlanarFace face)
        {
            // Get bounding edges of the face
            EdgeArray edges = face.EdgeLoops.get_Item(0);

            // Collect references for dimensioning
            ReferenceArray references = new ReferenceArray();
            List&amp;lt;XYZ&amp;gt; edgePoints = new List&amp;lt;XYZ&amp;gt;();

            foreach (Edge edge in edges)
            {
                Curve curve = edge.AsCurve();
                if (curve is Line line)
                {
                    // Add edge reference to the array
                    references.Append(edge.Reference);

                    // Add the endpoints of the line for dimensioning
                    edgePoints.Add(line.GetEndPoint(0));
                    edgePoints.Add(line.GetEndPoint(1));
                }
            }

            // Ensure at least two references for a valid dimension
            if (references.Size &amp;lt; 2 || edgePoints.Count &amp;lt; 2)
            {
                TaskDialog.Show("Error", "Not enough references to create a dimension.");
                return;
            }

            // Determine dimension line direction based on edge points
            XYZ dimensionStart = edgePoints.First();
            XYZ dimensionEnd = edgePoints.Last();

            // Calculate the direction between the points
            XYZ dimensionDirection = dimensionEnd - dimensionStart;

            // Debugging: Show dimension line information
            TaskDialog.Show("Dimension Info", $"Start: {dimensionStart}\nEnd: {dimensionEnd}\nDirection: {dimensionDirection}");

            // Ensure the direction is valid for dimensioning (avoid small magnitude)
            if (dimensionDirection.IsZeroLength())
            {
                TaskDialog.Show("Error", "The start and end points are identical, invalid dimension direction.");
                return;
            }

            // Define a minimum threshold for valid dimension size
            double minDimensionSize = 0.01;  // Example: 0.01 units as the threshold (can be adjusted)

            // Check if the dimension size is too small
            if (dimensionDirection.GetLength() &amp;lt; minDimensionSize)
            {
                TaskDialog.Show("Warning", "The dimension size is too small to be valid.");
                return; // Skip creating dimension for too small sizes
            }

            // Check that the direction vector is valid and non-zero
            if (dimensionDirection.IsZeroLength() || dimensionDirection.DotProduct(XYZ.BasisZ) &amp;lt; 0.001)
            {
                TaskDialog.Show("Error", "The dimension direction is invalid. Please ensure the edge is valid for dimensioning.");
                return;
            }

            // Proceed with dimension creation
            Line dimensionLine = Line.CreateBound(dimensionStart, dimensionEnd);
            

            // Create the dimension using the line direction
            doc.Create.NewDimension(view, dimensionLine, references);
        }







        /// &amp;lt;summary&amp;gt;
        /// Check if a face normal aligns with the view's direction.
        /// &amp;lt;/summary&amp;gt;
        private bool IsAlignedWithView(View view, XYZ normal)
        {
            if (view is ViewPlan || view is ViewSection)
            {
                // Get the view direction
                XYZ viewDirection = view.ViewDirection.Normalize();

                // Calculate the dot product between the face normal and view direction
                double dotProduct = Math.Abs(viewDirection.DotProduct(normal));

                // Log values for debugging
                TaskDialog.Show("Debug Info", $"Face Normal: {normal}\nView Direction: {viewDirection}\nDot Product: {dotProduct}");

                // Allow more tolerance for alignment (e.g., 0.95 instead of 0.99)
                return dotProduct &amp;gt; 0.95; // More tolerance for face alignment
            }

            return true; // Assume alignment for other view types
        }




        /// &amp;lt;summary&amp;gt;
        /// Check if a line lies in the plane of the view.
        /// &amp;lt;/summary&amp;gt;
        private bool IsLineInViewPlane(View view, Line line)
        {
            // Get the plane of the view
            Plane viewPlane = view.SketchPlane?.GetPlane();
            if (viewPlane == null) return false;

            // Validate each endpoint of the line
            return IsPointOnPlane(viewPlane, line.GetEndPoint(0)) &amp;amp;&amp;amp; IsPointOnPlane(viewPlane, line.GetEndPoint(1));
        }

        /// &amp;lt;summary&amp;gt;
        /// Verify if the face normal aligns with the view direction.
        /// &amp;lt;/summary&amp;gt;
        private bool IsFaceNormalAlignedWithView(View view, PlanarFace face)
        {
            // Get the view's direction
            XYZ viewDirection = view.ViewDirection.Normalize();

            // Get the face's normal
            XYZ faceNormal = face.FaceNormal.Normalize();

            // Check alignment (parallel or antiparallel)
            double dotProduct = faceNormal.DotProduct(viewDirection);

            // Allow small tolerance for floating-point comparison
            return Math.Abs(dotProduct) &amp;gt; 0.999; // 0.999 allows for minimal deviation
        }


        /// &amp;lt;summary&amp;gt;
        /// Check if a point lies on a given plane.
        /// &amp;lt;/summary&amp;gt;
        private bool IsPointOnPlane(Plane plane, XYZ point)
        {
            // Vector from the plane's origin to the point
            XYZ vector = point - plane.Origin;

            // Check if the vector is perpendicular to the plane's normal
            return Math.Abs(plane.Normal.DotProduct(vector)) &amp;lt; 1e-6; // Tolerance for floating-point comparison
        }



        private class ViewportSelectionFilter : ISelectionFilter
        {
            public bool AllowElement(Element element) =&amp;gt; element is Viewport;
            public bool AllowReference(Reference reference, XYZ position) =&amp;gt; false;
        }
       

        
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 04:14:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272714#M1365</guid>
      <dc:creator>DesignGroup01</dc:creator>
      <dc:date>2025-01-21T04:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272842#M1366</link>
      <description>&lt;LI-CODE lang="general"&gt;                    // Add the endpoints of the line for dimensioning
                    edgePoints.Add(line.GetEndPoint(0));
                    edgePoints.Add(line.GetEndPoint(1));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GetEndPoint will get a copy of it, so it lose when you do any change.&lt;/P&gt;&lt;P&gt;Try these instead.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                    List&amp;lt;ReferenceArray&amp;gt; refArrayPairs = new();

                    foreach (Edge edge in edges)
                    {
                        Curve curve = edge.AsCurve();
                        // create a pair
                        ReferenceArray refArrayPair = new ReferenceArray();
                        if (curve is Line line)  //Maybe an arc is fine, too.
                        {
                            // Add the endpoints of the line for dimensioning
                            refArrayPair.Append(curve.GetEndPointReference(0));
                            refArrayPair.Append(curve.GetEndPointReference(1));
                        }
                        if (refArrayPair.Size == 2)
                            refArrayPairs.Add(refArrayPair);
                    }&lt;/LI-CODE&gt;&lt;P&gt;*And then the dimension creating code should edit, too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 06:04:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272842#M1366</guid>
      <dc:creator>Sleepingfish_Kuo</dc:creator>
      <dc:date>2025-01-21T06:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272911#M1367</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void CreateDimensionsForFace(Document doc, View view, PlanarFace face)
{
    // Get bounding edges of the face
    EdgeArray edges = face.EdgeLoops.get_Item(0);

    // Collect references for dimensioning
    ReferenceArray references = new ReferenceArray();
    List&amp;lt;XYZ&amp;gt; edgePoints = new List&amp;lt;XYZ&amp;gt;();

    List&amp;lt;ReferenceArray&amp;gt; refArrayPairs = new();

    foreach (Edge edge in edges)
    {
        Curve curve = edge.AsCurve();
        // create a pair
        ReferenceArray refArrayPair = new ReferenceArray();
        if (curve is Line line)  //Maybe an arc is fine, too.
        {
            // Add the endpoints of the line for dimensioning
            refArrayPair.Append(curve.GetEndPointReference(0));
            refArrayPair.Append(curve.GetEndPointReference(1));
        }
        if (refArrayPair.Size == 2)
            refArrayPairs.Add(refArrayPair);
    }

    // Ensure at least two references for a valid dimension
    //if (references.Size &amp;lt; 2 || edgePoints.Count &amp;lt; 2)
    //{
    //    TaskDialog.Show("Error", "Not enough references to create a dimension.");
    //    return;
    //}

    // Determine dimension line direction based on edge points
    XYZ dimensionStart = edgePoints.First();
    XYZ dimensionEnd = edgePoints.Last();

    // Calculate the direction between the points
    XYZ dimensionDirection = dimensionEnd - dimensionStart;

    // Debugging: Show dimension line information
    TaskDialog.Show("Dimension Info", $"Start: {dimensionStart}\nEnd: {dimensionEnd}\nDirection: {dimensionDirection}");

    // Ensure the direction is valid for dimensioning (avoid small magnitude)
    if (dimensionDirection.IsZeroLength())
    {
        TaskDialog.Show("Error", "The start and end points are identical, invalid dimension direction.");
        return;
    }

    // Define a minimum threshold for valid dimension size
    double minDimensionSize = 0.01;  // Example: 0.01 units as the threshold (can be adjusted)

    // Check if the dimension size is too small
    if (dimensionDirection.GetLength() &amp;lt; minDimensionSize)
    {
        TaskDialog.Show("Warning", "The dimension size is too small to be valid.");
        return; // Skip creating dimension for too small sizes
    }

    // Check that the direction vector is valid and non-zero
    if (dimensionDirection.IsZeroLength() || dimensionDirection.DotProduct(XYZ.BasisZ) &amp;lt; 0.001)
    {
        TaskDialog.Show("Error", "The dimension direction is invalid. Please ensure the edge is valid for dimensioning.");
        return;
    }

    // Proceed with dimension creation
    Line dimensionLine = Line.CreateBound(dimensionStart, dimensionEnd);

    // Initialize a ReferenceArray to hold all the references
    ReferenceArray refArray = new ReferenceArray();

    // Add references to the ReferenceArray (for example, edge references)
    foreach (Edge edge in edges)
    {
        refArray.Append(edge.Reference);  // Add each edge's reference to the array
    }
    // Create the dimension using the line direction
    doc.Create.NewDimension(view, dimensionLine, refArray);
}&lt;/LI-CODE&gt;&lt;P&gt;I update the code as per your instruction &amp;amp; run the code.&lt;/P&gt;&lt;P&gt;"Error: Sequence contains no elements" get this error.&lt;BR /&gt;please help me, how to solve this error.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 06:54:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13272911#M1367</guid>
      <dc:creator>DesignGroup01</dc:creator>
      <dc:date>2025-01-21T06:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13273245#M1368</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sleepingfish_Kuo_0-1737454379413.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1457260iC6A032CAFFC45252/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sleepingfish_Kuo_0-1737454379413.png" alt="Sleepingfish_Kuo_0-1737454379413.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;use this for next step.&lt;/P&gt;&lt;P&gt;foreach refArrayPairs, test and create a dim.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 10:14:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13273245#M1368</guid>
      <dc:creator>Sleepingfish_Kuo</dc:creator>
      <dc:date>2025-01-21T10:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13273263#M1369</link>
      <description>&lt;P&gt;&lt;SPAN&gt;same issue again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"Error: Sequence contains no elements" get this error.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 10:25:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13273263#M1369</guid>
      <dc:creator>DesignGroup01</dc:creator>
      <dc:date>2025-01-21T10:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing Dimension in Assembly View: Prevent Value Change When Moved in Revit API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13274886#M1370</link>
      <description>&lt;P&gt;I didn't see your using "refArrayPair".&lt;/P&gt;&lt;P&gt;Since nothing is put in the list "edgepoint" but you're still using that, all codes are not working after that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 02:07:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/fixing-dimension-in-assembly-view-prevent-value-change-when/m-p/13274886#M1370</guid>
      <dc:creator>Sleepingfish_Kuo</dc:creator>
      <dc:date>2025-01-22T02:07:34Z</dc:date>
    </item>
  </channel>
</rss>

