<?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 how to get all vertecies of an entity solid3d in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6430917#M35408</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a door in a dwg file and using AutoCAD I would like to export all it's vertices. For now it exports just the extrude geometry. I would use an export tool but it's essential I get the layer name as well as the points in the same object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The type of objects I retrieve are either:&amp;nbsp;Solid3d, ExtrudedSurface, Line. But I am only interested in Solid3d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ioan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("EXPORTVERTICES")]
        public static void ThreeDocumentToFile()
        {

            var doc =
        Application.DocumentManager.MdiActiveDocument;

            // If we didn't find a document, return

            if (doc == null)
                return;

            // We could probably get away without locking the document
            // - as we only need to read - but it's good practice to
            // do it anyway

            using (var dl = doc.LockDocument())
            {
                var db = doc.Database;
                var ed = doc.Editor;
                
                // Capture our Extents3d objects in a list

                var sols = new List&amp;lt;DataMe&amp;gt;();

                using (var tr = doc.TransactionManager.StartTransaction())
                {
                    // Start by getting the modelspace

                    var ms =
                      (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db),
                        OpenMode.ForRead
                      );

                    // Get each Solid3d in modelspace and add its extents
                    // to the list
                    foreach (var id in ms)
                    {
                        var obj = tr.GetObject(id, OpenMode.ForRead);
                        var sol = obj as Solid3d;
                        
                        DataMe dataMe = new DataMe();
                        if (sol != null)
                        {
                            dataMe.extents = sol.GeometricExtents;
                            dataMe.layer = sol.Layer;
                        }

                        var pl = obj as Polyline;
                        if (pl != null)
                        {
                            Point3dCollection lst = new Point3dCollection();
                            int pts = pl.NumberOfVertices;
                            //ed.WriteMessage("\nNumber of params : " + (pts + 1).ToString());

                            for (int i = 0; i &amp;lt; (pts); i++)
                            {
                                lst.Add(pl.GetPointAtParameter(i));
                            }
                            foreach (Point3d p in lst)
                            {
                                //ed.WriteMessage("\nPoint :" + p.ToString());
                                dataMe.points.Add(p);
                            }
                        }
                        
                        

                        sols.Add(dataMe);
                    }
                    tr.Commit();
                }
                string output = GetSolidsString(sols);

                
                SaveFileDialog saveFileDialog1 = new SaveFileDialog("Save to json", "door.json", "json", "Save", SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension);
                
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    System.IO.File.WriteAllText(saveFileDialog1.Filename, output);
                }

            }
        }&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Jul 2016 09:55:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-07-12T09:55:59Z</dc:date>
    <item>
      <title>how to get all vertecies of an entity solid3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6430917#M35408</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a door in a dwg file and using AutoCAD I would like to export all it's vertices. For now it exports just the extrude geometry. I would use an export tool but it's essential I get the layer name as well as the points in the same object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The type of objects I retrieve are either:&amp;nbsp;Solid3d, ExtrudedSurface, Line. But I am only interested in Solid3d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ioan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("EXPORTVERTICES")]
        public static void ThreeDocumentToFile()
        {

            var doc =
        Application.DocumentManager.MdiActiveDocument;

            // If we didn't find a document, return

            if (doc == null)
                return;

            // We could probably get away without locking the document
            // - as we only need to read - but it's good practice to
            // do it anyway

            using (var dl = doc.LockDocument())
            {
                var db = doc.Database;
                var ed = doc.Editor;
                
                // Capture our Extents3d objects in a list

                var sols = new List&amp;lt;DataMe&amp;gt;();

                using (var tr = doc.TransactionManager.StartTransaction())
                {
                    // Start by getting the modelspace

                    var ms =
                      (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db),
                        OpenMode.ForRead
                      );

                    // Get each Solid3d in modelspace and add its extents
                    // to the list
                    foreach (var id in ms)
                    {
                        var obj = tr.GetObject(id, OpenMode.ForRead);
                        var sol = obj as Solid3d;
                        
                        DataMe dataMe = new DataMe();
                        if (sol != null)
                        {
                            dataMe.extents = sol.GeometricExtents;
                            dataMe.layer = sol.Layer;
                        }

                        var pl = obj as Polyline;
                        if (pl != null)
                        {
                            Point3dCollection lst = new Point3dCollection();
                            int pts = pl.NumberOfVertices;
                            //ed.WriteMessage("\nNumber of params : " + (pts + 1).ToString());

                            for (int i = 0; i &amp;lt; (pts); i++)
                            {
                                lst.Add(pl.GetPointAtParameter(i));
                            }
                            foreach (Point3d p in lst)
                            {
                                //ed.WriteMessage("\nPoint :" + p.ToString());
                                dataMe.points.Add(p);
                            }
                        }
                        
                        

                        sols.Add(dataMe);
                    }
                    tr.Commit();
                }
                string output = GetSolidsString(sols);

                
                SaveFileDialog saveFileDialog1 = new SaveFileDialog("Save to json", "door.json", "json", "Save", SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension);
                
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    System.IO.File.WriteAllText(saveFileDialog1.Filename, output);
                }

            }
        }&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jul 2016 09:55:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6430917#M35408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-12T09:55:59Z</dc:date>
    </item>
    <item>
      <title>Re : how to get all vertecies of an entity solid3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6430952#M35409</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the Brep (Boundary Representation) API.&lt;/P&gt;
&lt;P&gt;It requires to reference acdbmgdbrep.dll.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var pts = new Point3dCollection();
using (var brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(solid))
{
    foreach (var vertex in brep.Vertices)
    {
        pts.Add(vertex.Point);
    }
}&lt;/PRE&gt;
&lt;P&gt;Maybe &lt;A href="https://www.theswamp.org/index.php?topic=31865.msg445372#msg445372" target="_blank"&gt;this post&lt;/A&gt; give you more informations about the Brep API.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 10:24:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6430952#M35409</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-07-12T10:24:39Z</dc:date>
    </item>
    <item>
      <title>Re : how to get all vertecies of an entity solid3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6431977#M35410</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do these vertices have a integer ID or a way to reference them in order to create &lt;A href="http://stackoverflow.com/questions/15795348/generate-mesh-faces-for-vertices-in-three-js" target="_blank"&gt;faces&lt;/A&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following error in the way I am doing it:&amp;nbsp;cannot convert from 'Autodesk.AutoCAD.BoundaryRepresentation.Vertex' to 'Autodesk.AutoCAD.DatabaseServices.Vertex'&amp;nbsp;[...].&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;List&amp;lt;Vertex&amp;gt; vertexs = new List&amp;lt;Vertex&amp;gt;();
using (var brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(sol))
{
	foreach (var vertex in brep.Vertices)
	{
		VertexMe vertexMe = new VertexMe();
		vertexMe.Point = vertex.Point;
		//brep.Faces.First().Loops.First().Edges.First().Vertex1.
		foreach(var edge in vertex.Edges)
		{
			EdgeMe edgeMe = new EdgeMe();

			edgeMe.vertex1 = vertexs.IndexOf(edge.Vertex1); // &amp;lt;-- ERROR: 
			if (edgeMe.vertex1 == -1)
			{
				vertexs.Add(edge.Vertex1);
				edgeMe.vertex1 = vertexs.Count - 1;
			}

			edgeMe.vertex2 = vertexs.IndexOf(edge.Vertex2);
			if (edgeMe.vertex2 == -1)
			{
				vertexs.Add(edge.Vertex2);
				edgeMe.vertex2 = vertexs.Count - 1;
			}

			vertexMe.Edges.Add(edgeMe);
		}

		dataMe.points.Add(vertexMe);
	}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 17:37:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6431977#M35410</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-12T17:37:46Z</dc:date>
    </item>
    <item>
      <title>Re : how to get all vertecies of an entity solid3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6432088#M35411</link>
      <description>&lt;P&gt;I don't know anything about VertexMe type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you can directly get the faces using Brep.Faces property&lt;/P&gt;
&lt;P&gt;Each Face contains a loop collection you can get with Face.Loops property (external loop and eventually internal loops).&lt;/P&gt;
&lt;P&gt;Each BoundaryLoop contains an edges collection you can get with the BoundaryLoop.Edges property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code sample I linked upper shows the Brep tree architecture.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:22:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6432088#M35411</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-07-12T18:22:26Z</dc:date>
    </item>
    <item>
      <title>Re : how to get all vertecies of an entity solid3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6432264#M35412</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot for your help so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am trying to get the vertices, which works great for now. I have X Y Z coordinates for all of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I have to connect them in order to make them triangles. So I might have the first vertix connected with the 2nd and 3rd, the 5th with 1st and 6th and so on. I need a way to get those ids so that I have: X Y Z coordinates + vertex ID &amp;nbsp;++ List of adjacent edges [[2nd, 3rd], [5th, 1st]].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hoped the method below works but it doesn't. I found ids that are not connected to any vertices and ids that are duplicated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EdgeMe, VertexMe, DataMe are just data structures that help in serialising the data into json later on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public class EdgeMe
{
	public int vertex1;
	public int vertex2;
}
public class VertexMe
{
	public int id;
	public Point3d Point;
	public List&amp;lt;EdgeMe&amp;gt; Edges = new List&amp;lt;EdgeMe&amp;gt;();
}

public class DataMe{
	public Extents3d extents;
	public string layer;
	public List&amp;lt;VertexMe&amp;gt; points = new List&amp;lt;VertexMe&amp;gt;();
}


//...


// Get each Solid3d in modelspace and add its extents
// to the list
foreach (var id in ms)
{
	var obj = tr.GetObject(id, OpenMode.ForRead);
	var sol = obj as Solid3d;
	
	DataMe dataMe = new DataMe();
	if (sol != null)
	{
		dataMe.extents = sol.GeometricExtents;
		dataMe.layer = sol.Layer;
		using (var brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(sol))
		{
			foreach (var vertex in brep.Vertices)
			{
				VertexMe vertexMe = new VertexMe();
				vertexMe.Point = vertex.Point;
				vertexMe.id = vertex.Brep.GetHashCode();
				foreach(var edge in vertex.Edges)
				{
					EdgeMe edgeMe = new EdgeMe();
					edgeMe.vertex1 = edge.Vertex1.Brep.GetHashCode();
					edgeMe.vertex2 = edge.Vertex2.Brep.GetHashCode();
					vertexMe.Edges.Add(edgeMe);
				}

				dataMe.points.Add(vertexMe);
			}
		}
	}
	sols.Add(dataMe);
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jul 2016 19:19:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-all-vertecies-of-an-entity-solid3d/m-p/6432264#M35412</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-12T19:19:33Z</dc:date>
    </item>
  </channel>
</rss>

