<?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 Finding the Coordinates of the insertion point C# (.NET) in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7815321#M27073</link>
    <description>&lt;P&gt;Hi guys i'm currently doing a simple feature where I get a program to read then export the Name and Location of the insertion point to a .txt file.&lt;/P&gt;&lt;P&gt;I've managed to do the name of the block but I cant figure out for the life of me how to find the coordinates for the insertion point. Here is what I have so far any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.IO;
using System.Security;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace Extracting_Attributes
{
    public class GettingAtrributes
    {
        /// &amp;lt;exception cref="DirectoryNotFoundException"&amp;gt;The specified path is invalid (for example, it is on an unmapped drive). &amp;lt;/exception&amp;gt;
        /// &amp;lt;exception cref="SecurityException"&amp;gt;The caller does not have the required permission. &amp;lt;/exception&amp;gt;
        [CommandMethod("LISTATT")]
        public void ListAttributes()

        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Database db = HostApplicationServices.WorkingDatabase;

            Transaction tr = db.TransactionManager.StartTransaction();

            // Start the transaction

            try

            {
                // Build a filter list so that only block references are selected

                var filList = new TypedValue[1] {new TypedValue((Int32) DxfCode.Start, "INSERT")};

                var filter = new SelectionFilter(filList);

                var opts = new PromptSelectionOptions();

                opts.MessageForAdding = "Select block references: ";

                PromptSelectionResult res = ed.GetSelection(opts, filter);

                // Do nothing if selection is unsuccessful

                if (res.Status != PromptStatus.OK)

                    return;

                SelectionSet selSet = res.Value;

                ObjectId[] idArray = selSet.GetObjectIds();

                foreach (ObjectId blkId in idArray)

                {
                    var blkRef = (BlockReference) tr.GetObject(blkId, OpenMode.ForRead);


                    var btr = (BlockTableRecord) tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);

                    ed.WriteMessage("\nBlock: " + btr.Name);
                    System.IO.File.WriteAllText(@"C:\Users\robert.parsons\Documents\Attributes.txt", btr.Name);

                    btr.Dispose();

                    AttributeCollection attCol = blkRef.AttributeCollection;

                    foreach (ObjectId attId in attCol)

                    {
                        var attRef = (AttributeReference) tr.GetObject(attId, OpenMode.ForRead);

                        String str = "\n  Attribute Tag: " + attRef.Tag + "\n    Attribute String: " + attRef.TextString;
                        System.IO.File.WriteAllText(@"C:\Users\robert.parsons\Documents\Collection of Attributes.txt", str);
                        
                        
                        ed.WriteMessage(str);
                    }
                }

                tr.Commit();
            }

            catch (Autodesk.AutoCAD.Runtime.Exception ex)

            {
                ed.WriteMessage("Exception: " + ex.Message);
            }
            tr.Dispose();
        }
    }
}    

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 10:54:30 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-02-28T10:54:30Z</dc:date>
    <item>
      <title>Finding the Coordinates of the insertion point C# (.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7815321#M27073</link>
      <description>&lt;P&gt;Hi guys i'm currently doing a simple feature where I get a program to read then export the Name and Location of the insertion point to a .txt file.&lt;/P&gt;&lt;P&gt;I've managed to do the name of the block but I cant figure out for the life of me how to find the coordinates for the insertion point. Here is what I have so far any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.IO;
using System.Security;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace Extracting_Attributes
{
    public class GettingAtrributes
    {
        /// &amp;lt;exception cref="DirectoryNotFoundException"&amp;gt;The specified path is invalid (for example, it is on an unmapped drive). &amp;lt;/exception&amp;gt;
        /// &amp;lt;exception cref="SecurityException"&amp;gt;The caller does not have the required permission. &amp;lt;/exception&amp;gt;
        [CommandMethod("LISTATT")]
        public void ListAttributes()

        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Database db = HostApplicationServices.WorkingDatabase;

            Transaction tr = db.TransactionManager.StartTransaction();

            // Start the transaction

            try

            {
                // Build a filter list so that only block references are selected

                var filList = new TypedValue[1] {new TypedValue((Int32) DxfCode.Start, "INSERT")};

                var filter = new SelectionFilter(filList);

                var opts = new PromptSelectionOptions();

                opts.MessageForAdding = "Select block references: ";

                PromptSelectionResult res = ed.GetSelection(opts, filter);

                // Do nothing if selection is unsuccessful

                if (res.Status != PromptStatus.OK)

                    return;

                SelectionSet selSet = res.Value;

                ObjectId[] idArray = selSet.GetObjectIds();

                foreach (ObjectId blkId in idArray)

                {
                    var blkRef = (BlockReference) tr.GetObject(blkId, OpenMode.ForRead);


                    var btr = (BlockTableRecord) tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);

                    ed.WriteMessage("\nBlock: " + btr.Name);
                    System.IO.File.WriteAllText(@"C:\Users\robert.parsons\Documents\Attributes.txt", btr.Name);

                    btr.Dispose();

                    AttributeCollection attCol = blkRef.AttributeCollection;

                    foreach (ObjectId attId in attCol)

                    {
                        var attRef = (AttributeReference) tr.GetObject(attId, OpenMode.ForRead);

                        String str = "\n  Attribute Tag: " + attRef.Tag + "\n    Attribute String: " + attRef.TextString;
                        System.IO.File.WriteAllText(@"C:\Users\robert.parsons\Documents\Collection of Attributes.txt", str);
                        
                        
                        ed.WriteMessage(str);
                    }
                }

                tr.Commit();
            }

            catch (Autodesk.AutoCAD.Runtime.Exception ex)

            {
                ed.WriteMessage("Exception: " + ex.Message);
            }
            tr.Dispose();
        }
    }
}    

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 10:54:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7815321#M27073</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-28T10:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Coordinates of the insertion point C# (.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7815648#M27074</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the block reference insertion point with its Position property:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;blkRef.Position&lt;/PRE&gt;
&lt;P&gt;But it seems to me there's something curious the way you write the txt file.&lt;/P&gt;
&lt;P&gt;For each selected block reference, the C:\Users\robert.parsons\Documents\Attributes.txt file is overwritten.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 12:39:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7815648#M27074</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-28T12:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Coordinates of the insertion point C# (.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7816417#M27075</link>
      <description>&lt;P&gt;Perhaps you can get some inspiration from this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("LISTATT")]
        public void ListAttributes()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var filter = new SelectionFilter(new[] { new TypedValue(0, "INSERT") });
            var opts = new PromptSelectionOptions();
            opts.MessageForAdding = "Select block references: ";
            var res = ed.GetSelection(opts, filter);
            if (res.Status != PromptStatus.OK)
                return;
            string str = "";
            using (var tr = db.TransactionManager.StartTransaction())
            {
                foreach (SelectedObject so in res.Value)
                {
                    var br = (BlockReference)tr.GetObject(so.ObjectId, OpenMode.ForRead);
                    str += $"{br.Name} {br.Position:0.00}\r\n";
                    if (br.AttributeCollection.Count &amp;gt; 0)
                    {
                        str += "Attributes:\r\n";
                        foreach (ObjectId id in br.AttributeCollection)
                        {
                            var att = (AttributeReference)id.GetObject(OpenMode.ForRead);
                            str += $"\tTag: {att.Tag} Text: {att.TextString}\r\n";
                        }
                    }&lt;BR /&gt;                    str += "\r\n";
                }
                tr.Commit();
            }
            ed.WriteMessage(str);
            System.IO.File.WriteAllText(@"C:\Users\robert.parsons\Documents\Attributes.txt", str);;
        }&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 15:51:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7816417#M27075</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-28T15:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Coordinates of the insertion point C# (.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7819008#M27076</link>
      <description>&lt;P&gt;Thank I did change it to WriteAllLines&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 11:35:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/finding-the-coordinates-of-the-insertion-point-c-net/m-p/7819008#M27076</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-01T11:35:02Z</dc:date>
    </item>
  </channel>
</rss>

