.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 4 (209 Views)

Getting the coordinate of the lastly appended(added) point object

209 Views, 3 Replies
05-02-2012 10:02 PM

Hi,

 

I am trying to get the coordinate of the lastly appended(added) point object.

It seems like I need to use "ObjectAppended" event.

However, when the event is triggred, it looks like the sender object is "Database" (not Point object).

 

How could I retrieve the point object therefore the coordinates of the point using "Database" (sender object)?

 

(explaination with C# code would be much more thanksful)

 

Jake.

Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 2 of 4 (199 Views)

Re: Getting the coordinate of the lastly appended(added) point object

05-02-2012 11:52 PM in reply to: dynamicscope

I encountered with another problem.

If I use "ObjectAppended" event, I cannot get the coordinates value as a return value.

I need the coordinate value in order to manipulate some other variables.

How can I approach this problem?

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (188 Views)

Re: Getting the coordinate of the lastly appended(added) point object

05-03-2012 03:06 AM in reply to: dynamicscope

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
*Expert Elite*
Alfred.NESWADBA
Posts: 9,398
Registered: ‎06-29-2007
Message 4 of 4 (171 Views)

Re: Getting the coordinate of the lastly appended(added) point object

05-03-2012 01:29 PM in reply to: dynamicscope

Hi,

 

it may not work for your task, it's not really what you asked for, but it may also be what you may search for and so just to be mentioned:

Sysvar LASTPOINT (>>>details<<<)

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!