This is my codes:
[CommandMethod("Test")]
static public void test() // This method can have any name
{
// Put your command code here
Editor ed=Application.DocumentManager.MdiActiveDocument.Editor;
ObjectId id=ed.GetEntity("Select an entity").ObjectId;
Database db=Application.DocumentManager.MdiActiveDocument.Database;
DBTransMan tm=db.TransactionManager;
using(Transaction trans=tm.StartTransaction())
{
Dimension dim=(Dimension)tm.GetObject(id,OpenMode.ForRead);
ObjectId dimId=dim.Dimblk1;
DBObject obj=tm.GetObject(dimId,OpenMode.ForRead);
ed.WriteMessage(obj.GetType().ToString());
}
}
When I run this program,I get the following exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Autodesk.AutoCAD.Runtime.Exception: eInvalidObjectId