Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this following code which extracts x,y coordinates of a Block in the model space.
Could someone please help to know how I can extract the Lat Long of these coordinates, given that Geolocation is already set up in the drawing.
Thanks in advance.
public class Class1
{
[CommandMethod("TEST")]
public static void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var peo = new PromptEntityOptions("\nSelect Block A: ");
peo.SetRejectMessage("\nSelected object is not a block.");
peo.AddAllowedClass(typeof(BlockReference), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var br = (BlockReference)tr.GetObject(per.ObjectId, OpenMode.ForRead);
var btr = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
foreach (ObjectId id in btr)
{
if (id.ObjectClass.Name == "AcDbBlockReference")
{
var nested = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
var position = nested.Position.TransformBy(br.BlockTransform);
ed.WriteMessage($"\nPosition of block '{nested.Name}': {position}");
break;
}
}
tr.Commit();
}
}
}
Solved! Go to Solution.