<?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 entity coordinates in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/entity-coordinates/m-p/12379038#M6618</link>
    <description>&lt;P&gt;Is there a way of getting the coordinates of every entity. I know how to get the vertices coordinates of a polylines but I want to iterate through all entities in model space and move them to a 0 z coordinate if it is not at 0 already.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2023 14:25:18 GMT</pubDate>
    <dc:creator>gwhitcherQ98HZ</dc:creator>
    <dc:date>2023-11-15T14:25:18Z</dc:date>
    <item>
      <title>entity coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/entity-coordinates/m-p/12379038#M6618</link>
      <description>&lt;P&gt;Is there a way of getting the coordinates of every entity. I know how to get the vertices coordinates of a polylines but I want to iterate through all entities in model space and move them to a 0 z coordinate if it is not at 0 already.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 14:25:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/entity-coordinates/m-p/12379038#M6618</guid>
      <dc:creator>gwhitcherQ98HZ</dc:creator>
      <dc:date>2023-11-15T14:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: entity coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/entity-coordinates/m-p/12380458#M6619</link>
      <description>&lt;P&gt;All entities have at least one coordinate, but each class elaborates them&amp;nbsp; differently, so approaching the problem using coordinates is difficult as it requires you to deal with each type of entity using a different code path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a much simpler way to do it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;using Autodesk.AutoCAD.Geometry;
using AcRx = Autodesk.AutoCAD.Runtime;

namespace Autodesk.AutoCAD.DatabaseServices.MyEntityExtensions;

public static class EntityExtensions
{
   public static bool TranslateToXYPlane(this Entity entity)
   {
      if(entity == null)
         throw new ArgumentNullException(nameof(entity));
      double z = entity.GetBoundingBox().MinPoint.Z;
      if(Math.Abs(z) &amp;gt; 1.0e-5)
      {
         if(!entity.IsWriteEnabled)
            entity.UpgradeOpen();
         entity.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, z).Negate()));
         return true;
      }
      return false;
   }

   /// &amp;lt;comments&amp;gt;
   /// We can't universally use GeometryExtentsBestFit() on any
   /// block reference without risking an exception, which happens
   /// with non uniformly-scaled block references. This code tries 
   /// to work around it, but falls-back with non uniformly-scaled
   /// block references, resulting in a possibly-erroneous result.
   /// &amp;lt;/comments&amp;gt;

   public static Extents3d GetBoundingBox(this Entity entity)
   {
      if(entity is BlockReference br)
      {
         try
         {
            return br.GeometryExtentsBestFit(Matrix3d.Identity);
         }
         catch(AcRx.Exception ex)
         {
            if(ex.ErrorStatus != AcRx.ErrorStatus.InvalidInput)  // NUS blockref
               throw ex;
         }
      }
      return entity.GeometricExtents;
   }
   
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Open each each entity, and invoke the TranslateToXYPlane() extension method on it.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 03:40:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/entity-coordinates/m-p/12380458#M6619</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-11-16T03:40:01Z</dc:date>
    </item>
  </channel>
</rss>

