<?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: Get the vertices points of a polygon in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11356416#M17662</link>
    <description>&lt;P&gt;I Have found the solution and I put the code here. The code returns vertices on the top surface of a floor. User selects the Floor and its&amp;nbsp; upper vertices and Location of them will be shown.&lt;/P&gt;&lt;P&gt;Thanks to my friend &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12236593"&gt;@ahmedsherif9220&lt;/a&gt;&amp;nbsp; for his guides.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Collections;
using ElementFiltering;
//using System.Windows.Forms;
using Autodesk.Revit.DB.DirectContext3D;

namespace GetVertices
{
    [Transaction(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    internal partial class GetVertices : IExternalCommand
    {
        //  member variables 
        Application m_rvtApp;
        Document m_rvtDoc;

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //  Get the access to the top most objects
            UIApplication rvtUIApp = commandData.Application;
            UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
            //m_rvtApp = rvtUIApp.Application;
            m_rvtDoc = rvtUIDoc.Document;

            Reference SelElem = rvtUIDoc.Selection.PickObject(ObjectType.Element, "Please Select a Floor!");
            Element elem = m_rvtDoc.GetElement(SelElem);


            // Options For Geometry
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.DetailLevel = ViewDetailLevel.Fine;

            PlanarFace planarTopface = null;
            FaceArray faces = null;
            Face topFace = null;


            GeometryElement elemGeom = elem.get_Geometry(opt);
            foreach (GeometryObject geomObj in elemGeom)
            {
                Solid geomSolid = geomObj as Solid;
                faces = geomSolid.Faces;
                //GetTopFaceOfElement(geomSolid);
                foreach (Face f in faces)
                {
                    PlanarFace pf = f as PlanarFace;
                    if (pf.FaceNormal.IsAlmostEqualTo(new XYZ(0, 0, 1)))
                    {
                        planarTopface = pf;
                        topFace = pf;
                    }
                }
            }

            CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
            Array curves1 = curves;
            List&amp;lt;XYZ&amp;gt; points = new List&amp;lt;XYZ&amp;gt;();
            List&amp;lt;Line&amp;gt; linesAround = new List&amp;lt;Line&amp;gt;();


            foreach (CurveLoop i in curves1)
            {
                foreach (Line l in i)
                {
                    var curve = l as Curve;
                    var pointsofcurve = curve.Tessellate();
                    linesAround.Add(l);
                    //now you have the two points of the curve
                    foreach (XYZ point in pointsofcurve)
                    {
                        points.Add(point);
                    }
                }
            }

            List&amp;lt;XYZ&amp;gt; verts = new List&amp;lt;XYZ&amp;gt;();

            // Adding points to  vertices list which is called  verts
            int z = 0;
            while (z &amp;lt; points.Count)
            {
                verts.Add(points[z]);
                z = z + 2;
            }

            string s = null;
            for(int v=0; v &amp;lt; verts.Count; v++)
            {
                s+="Vertex "+(v+1).ToString()+" Location is: "+$"({verts[v].X},{verts[v].Y},{verts[v].Z})\n";
            }

            TaskDialog.Show("Vertices of Selected Floor Information", "Number Of Detected Lines: " + linesAround.Count.ToString() + "\nNumber Of Detected Vertices: " + verts.Count.ToString()+"\n"+s);

            return Result.Succeeded;
        }&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 12 Aug 2022 18:03:13 GMT</pubDate>
    <dc:creator>Ali.sadeghi.h1994</dc:creator>
    <dc:date>2022-08-12T18:03:13Z</dc:date>
    <item>
      <title>Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11340266#M17655</link>
      <description>&lt;P&gt;Hi everyone. I wish you a good day.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;I am looking for a way to get the coordinates of the vertices of a polygon(or get the vertices points as point) and then place the desired element on each vertex.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;I know how to place the element on the points, but I can't write a code to get the vertices points of the selected polygon (automatically).&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Vertices.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1100425i43286EF5CA7651CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vertices.png" alt="Vertices.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;I would be very grateful if someone could guide me.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 15:08:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11340266#M17655</guid>
      <dc:creator>Ali.sadeghi.h1994</dc:creator>
      <dc:date>2022-08-04T15:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11344671#M17656</link>
      <description>&lt;P&gt;Good Morning,&amp;nbsp;&lt;/P&gt;&lt;P&gt;you will find the answer here&amp;nbsp;&lt;A href="https://thebuildingcoder.typepad.com/blog/2010/02/getpolygon-extension-methods.html" target="_blank"&gt;The Building Coder: GetPolygon Extension Methods (typepad.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;hope it will help you.&lt;/P&gt;&lt;P&gt;sherif&lt;/P&gt;</description>
      <pubDate>Sun, 07 Aug 2022 09:24:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11344671#M17656</guid>
      <dc:creator>ahmedsherif9220</dc:creator>
      <dc:date>2022-08-07T09:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11349656#M17657</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;That link helped me to solve a part of my problem that was getting Top Face of a floor or any other elements. Mentioned part is first step to get vertices of a Face(ex. Top Face of a floor). I put the code here and I found a way get to the vertices but it still doesn't work. The way is that I think we can get CurveLoop Lines and then access them and their parameters but unfortunately my code does not work. In the code below we can get the Top Face of a Floor in the line that I marked with ( //*******Get Top Face*******) and the codes after that does not work to get Lines of the CurveLoop. If you know the error please correct it. ( It should be mentioned that I need Vertices at the end but I couldn't get them).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Collections;
using ElementFiltering;
//using System.Windows.Forms;
using Autodesk.Revit.DB.DirectContext3D;

namespace GetTopFace
{
    [Transaction(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    internal partial class GetFace : IExternalCommand
    {
        Application m_rvtApp;
        Document m_rvtDoc;

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            UIApplication rvtUIApp = commandData.Application;
            UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
            //m_rvtApp = rvtUIApp.Application;
            m_rvtDoc = rvtUIDoc.Document;

            Reference SelElem = rvtUIDoc.Selection.PickObject(ObjectType.Element, "Please Select First Floor!");
            Element elem = m_rvtDoc.GetElement(SelElem);


            // Options For Geometry
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.DetailLevel = ViewDetailLevel.Fine;

            PlanarFace planarTopface = null;
            FaceArray faces = null;
            Face topFace = null;


            GeometryElement elemGeom = elem.get_Geometry(opt);
            foreach (GeometryObject geomObj in elemGeom)
            {
                Solid geomSolid = geomObj as Solid;
                faces = geomSolid.Faces;
                //GetTopFaceOfElement;            //*******Get Top Face*******
                foreach (Face f in faces)
                {
                    PlanarFace pf = f as PlanarFace;
                    if (pf.FaceNormal.IsAlmostEqualTo(new XYZ(0, 0, 1)))
                    {
                        planarTopface = pf;
                        topFace = pf;
                    }
                }
            }


            // ??????How to Get Lines of CurveLoop of the TopFace ????????  --  it does not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  --
            CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
            Array curves1 = curves;
            Line[] lines = null;
            foreach (CurveLoop i in curves1)
            {
                foreach (Line l in i)
                {
                    lines.Append(l);
                }
            }

            return Result.Succeeded;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 19:14:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11349656#M17657</guid>
      <dc:creator>Ali.sadeghi.h1994</dc:creator>
      <dc:date>2022-08-09T19:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350088#M17658</link>
      <description>&lt;P&gt;ok you need the vertex,&lt;/P&gt;&lt;P&gt;from planar face you got the lines&amp;nbsp;&lt;BR /&gt;cast it in curves then tesselate then you got your points&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
            Array curves1 = curves;
            XYZ[] points= null;
            foreach (CurveLoop i in curves1)
            {
                foreach (Line l in i)
                {
                   var curve = l as Curve;
                  var pointsofcuvre =  curve.Tesselate();
// noww you have the two points of the curve
                 foreach(point in pointsofcurve)
                 {
                 points.add(point);
                 }
                }
            }

            return Result.Succeeded;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 00:07:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350088#M17658</guid>
      <dc:creator>ahmedsherif9220</dc:creator>
      <dc:date>2022-08-10T00:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350757#M17659</link>
      <description>&lt;P&gt;Thanks again for your&amp;nbsp; guides and useful tips.&lt;/P&gt;&lt;P&gt;That seems to be correct but when second foreach loop wants to add the point&amp;nbsp; to the defined List of XYZ, an error appears. I think I have to use a copy of point not the reference point but I don't know how. Below I've put screenshot of the error.&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Error.JPG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1102326i0A275F25B6A062FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Error.JPG" alt="Error.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 08:57:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350757#M17659</guid>
      <dc:creator>Ali.sadeghi.h1994</dc:creator>
      <dc:date>2022-08-10T08:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350974#M17660</link>
      <description>&lt;P&gt;hola ali&lt;/P&gt;&lt;P&gt;send me the project please and i will fix it to you&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 11:43:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11350974#M17660</guid>
      <dc:creator>ahmedsherif9220</dc:creator>
      <dc:date>2022-08-10T11:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11351018#M17661</link>
      <description>&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try that it will give you the number of vertix&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;				UIDocument uidoc = this.Application.ActiveUIDocument;
			Document doc = uidoc.Document;
			var x = uidoc.Selection.PickObject(ObjectType.Element);
			Element elem = doc.GetElement(x);


            // Options For Geometry
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.DetailLevel = ViewDetailLevel.Fine;

            PlanarFace planarTopface = null;
            FaceArray faces = null;
            Face topFace = null;
           List&amp;lt;XYZ&amp;gt; points = new List&amp;lt;XYZ&amp;gt;();
			            

            GeometryElement elemGeom = elem.get_Geometry(opt);
            foreach (GeometryObject geomObj in elemGeom)
            {
                Solid geomSolid = geomObj as Solid;
                faces = geomSolid.Faces;
                //GetTopFaceOfElement;            //*******Get Top Face*******
                foreach (Face f in faces)
                {
                    PlanarFace pf = f as PlanarFace;
                    if (pf.FaceNormal.IsAlmostEqualTo(new XYZ(0, 0, 1)))
                    {
                        planarTopface = pf;
                        topFace = pf;
                    }
                }
            }


			            // ??????How to Get Lines of CurveLoop of the TopFace ????????  --  it does not work   --
			            CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
			            Array curves1 = curves;
			           foreach (CurveLoop i in curves1)
			            {
			                foreach (Line l in i)
			                {
			                   var curve = l as Curve;
			                   var pointsofcuvre =  curve.Tessellate();
							// noww you have the two points of the curve
							points.AddRange(pointsofcuvre.ToList());
			                }
			            }
			           TaskDialog.Show("sfdsf",points.Count.ToString());&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 12:05:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11351018#M17661</guid>
      <dc:creator>ahmedsherif9220</dc:creator>
      <dc:date>2022-08-10T12:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Get the vertices points of a polygon</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11356416#M17662</link>
      <description>&lt;P&gt;I Have found the solution and I put the code here. The code returns vertices on the top surface of a floor. User selects the Floor and its&amp;nbsp; upper vertices and Location of them will be shown.&lt;/P&gt;&lt;P&gt;Thanks to my friend &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12236593"&gt;@ahmedsherif9220&lt;/a&gt;&amp;nbsp; for his guides.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Collections;
using ElementFiltering;
//using System.Windows.Forms;
using Autodesk.Revit.DB.DirectContext3D;

namespace GetVertices
{
    [Transaction(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    internal partial class GetVertices : IExternalCommand
    {
        //  member variables 
        Application m_rvtApp;
        Document m_rvtDoc;

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //  Get the access to the top most objects
            UIApplication rvtUIApp = commandData.Application;
            UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
            //m_rvtApp = rvtUIApp.Application;
            m_rvtDoc = rvtUIDoc.Document;

            Reference SelElem = rvtUIDoc.Selection.PickObject(ObjectType.Element, "Please Select a Floor!");
            Element elem = m_rvtDoc.GetElement(SelElem);


            // Options For Geometry
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.DetailLevel = ViewDetailLevel.Fine;

            PlanarFace planarTopface = null;
            FaceArray faces = null;
            Face topFace = null;


            GeometryElement elemGeom = elem.get_Geometry(opt);
            foreach (GeometryObject geomObj in elemGeom)
            {
                Solid geomSolid = geomObj as Solid;
                faces = geomSolid.Faces;
                //GetTopFaceOfElement(geomSolid);
                foreach (Face f in faces)
                {
                    PlanarFace pf = f as PlanarFace;
                    if (pf.FaceNormal.IsAlmostEqualTo(new XYZ(0, 0, 1)))
                    {
                        planarTopface = pf;
                        topFace = pf;
                    }
                }
            }

            CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
            Array curves1 = curves;
            List&amp;lt;XYZ&amp;gt; points = new List&amp;lt;XYZ&amp;gt;();
            List&amp;lt;Line&amp;gt; linesAround = new List&amp;lt;Line&amp;gt;();


            foreach (CurveLoop i in curves1)
            {
                foreach (Line l in i)
                {
                    var curve = l as Curve;
                    var pointsofcurve = curve.Tessellate();
                    linesAround.Add(l);
                    //now you have the two points of the curve
                    foreach (XYZ point in pointsofcurve)
                    {
                        points.Add(point);
                    }
                }
            }

            List&amp;lt;XYZ&amp;gt; verts = new List&amp;lt;XYZ&amp;gt;();

            // Adding points to  vertices list which is called  verts
            int z = 0;
            while (z &amp;lt; points.Count)
            {
                verts.Add(points[z]);
                z = z + 2;
            }

            string s = null;
            for(int v=0; v &amp;lt; verts.Count; v++)
            {
                s+="Vertex "+(v+1).ToString()+" Location is: "+$"({verts[v].X},{verts[v].Y},{verts[v].Z})\n";
            }

            TaskDialog.Show("Vertices of Selected Floor Information", "Number Of Detected Lines: " + linesAround.Count.ToString() + "\nNumber Of Detected Vertices: " + verts.Count.ToString()+"\n"+s);

            return Result.Succeeded;
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 18:03:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-the-vertices-points-of-a-polygon/m-p/11356416#M17662</guid>
      <dc:creator>Ali.sadeghi.h1994</dc:creator>
      <dc:date>2022-08-12T18:03:13Z</dc:date>
    </item>
  </channel>
</rss>

