Here is a sample code, change to your suit
[CommandMethod("huh")]
public void AddPointEvents()
{
// Get the current document and database, and start a transaction
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
DBPoint dpoint = null;
db.ObjectAppended += new ObjectEventHandler(db_ObjectAppended);
Editor ed=doc.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Open the current space for write
BlockTableRecord btr;
btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Point3d pt;
PromptPointResult pres;
pres= ed.GetPoint("\nPick a point: ");
if (pres.Status != PromptStatus.OK) return;
// Create a point
// pres = ed.GetPoint("\nPick a point: ");
pt = pres.Value;
dpoint = new DBPoint();
dpoint.Position = pt;//<-- position changed separatelly to call db.ObjectAppended event
// Add the new point to the block table record and the transaction
btr.AppendEntity(dpoint);
tr.AddNewlyCreatedDBObject(dpoint, true);
// Save the new object to the database
tr.Commit();
db.ObjectAppended -= new ObjectEventHandler(db_ObjectAppended);
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message+"\n" + ex.StackTrace);
}
finally
{
}
}
public void db_ObjectAppended(object sender, ObjectEventArgs e)
{
// Get the current document and database, and start a StartOpenCloseTransaction
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
try
{
DBObject dbo = e.DBObject;
DBPoint dpoint = dbo as DBPoint;
Point3d ins = dpoint.Position;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
("\nCoordinates:\tX = {0}; Y = {1}; Z = {2}", ins.X, ins.Y, ins.Z);
}
catch (System.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
(ex.Message + "\n" + ex.StackTrace);
}
tr.Commit();
}
}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919