<?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: DraworderTable from a Xref in c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365765#M6675</link>
    <description>If on top entity is xref, you can open entity.BlockId as BlockTableRecord and get top entity in this. But that might not be a pline.</description>
    <pubDate>Thu, 09 Nov 2023 13:43:40 GMT</pubDate>
    <dc:creator>cuongtk2</dc:creator>
    <dc:date>2023-11-09T13:43:40Z</dc:date>
    <item>
      <title>DraworderTable from a Xref in c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365628#M6674</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;What I want: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I have a drawing, in this drawing it has 1-n Xref. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;In the xref it has 3dPoly, 2dPoly, lines and arcs. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Also in the drawing it has 3dpoly, 2dpoly, lines and arcs. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I have a function that returns all ObjectIds of entities that are on top of each other. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;These can also be entities that are in Xref. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;What I need is a function that tells me which entity is on top. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;e.g. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Current drawing has 2 polylines on top of each other. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The drawing has 2 xrefs, each of which also has 2 polylines on top of each other. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;So I have 6 entities that are on top of each other. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The function has to return the entity that is on top.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Is that even possible?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 12:46:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365628#M6674</guid>
      <dc:creator>hsiegenthaler</dc:creator>
      <dc:date>2023-11-09T12:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: DraworderTable from a Xref in c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365765#M6675</link>
      <description>If on top entity is xref, you can open entity.BlockId as BlockTableRecord and get top entity in this. But that might not be a pline.</description>
      <pubDate>Thu, 09 Nov 2023 13:43:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365765#M6675</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2023-11-09T13:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: DraworderTable from a Xref in c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365775#M6676</link>
      <description>&lt;P&gt;First - Thank you for you repley&lt;/P&gt;&lt;P&gt;Ok and how I'm doing that?&lt;/P&gt;&lt;P&gt;any definitions/method for doing that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: I but my code&lt;/P&gt;&lt;P&gt;At row 197 start the function where I need, to evaluete the top entity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 13:58:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12365775#M6676</guid>
      <dc:creator>hsiegenthaler</dc:creator>
      <dc:date>2023-11-09T13:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: DraworderTable from a Xref in c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12368146#M6677</link>
      <description>&lt;LI-CODE lang="general"&gt;internal class CadClass1
{
    [CommandMethod("NCv")]
    
    public static void ncv()
    {
        Document doc = AcadApp.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;
        var ed = doc.Editor; 
        var ptr = ed.GetPoint("\nPick point");
        if (ptr.Status == PromptStatus.OK) 
        {
            var pt = ptr.Value;
            ObjectNear objnear = new ObjectNear() { Id = ObjectId.Null, Z = -100 }; 
            using (DocumentLock lk = doc.LockDocument())
            {
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    var cspace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
                    objnear = FindNearPoint(cspace, pt, objnear, tr);
                }
            }  
            ed.WriteMessage("Top curve Id: " + objnear.Id.ToString() + ", and Z:" + objnear.Z.ToString());
        }            
    }   

    /// &amp;lt;summary&amp;gt;
    /// class to save ObjectId and MaxZ
    /// &amp;lt;/summary&amp;gt;
    internal class ObjectNear
    {
        public ObjectId Id { get; set; }
        public double Z { get; set; }
    }

    /// &amp;lt;summary&amp;gt;
    /// Check distance from point3d to curve on XY plane &amp;lt; 0.01 
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="cv"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="pt"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    private static bool IsPointNearCurve(Curve cv, Point3d pt)
    {
        var pc = cv.GetClosestPointTo(pt, false);
        return pt.Convert2d(new Plane()).GetDistanceTo(pc.Convert2d(new Plane())) &amp;lt; 0.01;            
    }

    /// &amp;lt;summary&amp;gt;
    /// Get Elevation of pickpoint on curve 
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="cv"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="pickpoint"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    private static double GetZpoint(Curve cv, Point3d pickpoint) =&amp;gt; cv.GetClosestPointTo(pickpoint, false).Z;

    /// &amp;lt;summary&amp;gt;
    /// Find curve near a point from BTR currentspace
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="btr"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="pickpoint"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="objnear"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="tr"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt; 
    private static ObjectNear FindNearPoint(BlockTableRecord btr, Point3d pickpoint, ObjectNear objnear, Transaction tr)
    {           
            foreach (ObjectId item in btr)
            {
                var ent = tr.GetObject(item, OpenMode.ForRead) as Entity;
                if (ent is Curve cv)
                {
                    if (IsPointNearCurve(cv, pickpoint) &amp;amp;&amp;amp; objnear.Z &amp;lt;= GetZpoint(cv, pickpoint))
                    {
                        objnear.Id = cv.Id;
                        objnear.Z = GetZpoint(cv, pickpoint);
                    }
                }
                else if (ent is BlockReference br )
                {
                    var matrix = br.BlockTransform;
                    var newpt = pickpoint.TransformBy(matrix);
                    var btrblock = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;                       
                    objnear = FindNearPoint(btrblock, newpt, objnear, tr);
                }
            }  
        return objnear;
    }         
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 10 Nov 2023 09:58:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/drawordertable-from-a-xref-in-c/m-p/12368146#M6677</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2023-11-10T09:58:02Z</dc:date>
    </item>
  </channel>
</rss>

