Message 1 of 4

Not applicable
02-28-2018
02:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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.
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 { /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive). </exception> /// <exception cref="SecurityException">The caller does not have the required permission. </exception> [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(); } } }
Solved! Go to Solution.