.NET

Reply
Contributor
cschildmeier
Posts: 15
Registered: ‎06-21-2006
Message 1 of 4 (180 Views)
Accepted Solution

Obtain Northing/Easting

180 Views, 3 Replies
04-16-2014 12:38 PM

Am I just not looking in the right spot or do I need to do maths to figure it out?  There are common things that are obviously easy to grab out of Autodesk.AutoCAD.DatabaseServices.Line(length/start point etc) but northing/easting aren't in there.  

The end points should be in X,Y,Z format. 

 

Y = Northing and X = Easting

 

*Expert Elite*
rkmcswain
Posts: 3,592
Registered: ‎11-13-2006
Message 2 of 4 (175 Views)

Re: Obtain Northing/Easting

04-16-2014 12:47 PM in reply to: cschildmeier

The end points should be in X,Y,Z format. 

 

Y = Northing and X = Easting

 

Contributor
cschildmeier
Posts: 15
Registered: ‎06-21-2006
Message 3 of 4 (168 Views)

Re: Obtain Northing/Easting

04-16-2014 01:04 PM in reply to: rkmcswain

AcDb.Line.Endpoint.X/Y/Z

 

Just as simple as I expected it should be.

 

Thanks!

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

Re: Obtain Northing/Easting

04-16-2014 05:39 PM in reply to: cschildmeier
    
// place some points on screen, set 'pdmode' to 34 (optional)
// then select all points
// not sure about formatting, probably it's need to remove space
// between char and number, so let me know about

      [CommandMethod("lx")]
        public static void PointLabeling()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            Matrix3d ucs = ed.CurrentUserCoordinateSystem;

            TypedValue[] filter = { new TypedValue((int)DxfCode.Start, "POINT") };

            SelectionFilter filterSset = new SelectionFilter(filter);

            PromptSelectionOptions pso = new PromptSelectionOptions();

           // pso.SingleOnly = true;//comment this if you want to label multiple polylines

            pso.MessageForAdding = "Select points to label >> ";

            PromptSelectionResult psr = ed.GetSelection(pso, filterSset);

            if (psr.Status != PromptStatus.OK)
                return;
            PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter text size: ");
            pdo.AllowZero = true;
            pdo.AllowNone = true;
            pdo.UseDefaultValue = true;
            pdo.DefaultValue = db.Textsize;

            PromptDoubleResult res;

            res = ed.GetDouble(pdo);

            if (res.Status != PromptStatus.OK)
                return;

            double theight = res.Value;
            if (theight == 0)

                theight = 0.2;
            Transaction tr = db.TransactionManager.StartTransaction();

            using (tr)
            {
                try
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                    ObjectId[] ids = psr.Value.GetObjectIds();



                    for (int i = 0; i < ids.Length; i++)
                    {
                      
                        DBPoint dpt = tr.GetObject(ids[i], OpenMode.ForRead) as DBPoint;
                       
                        Point3d lp = dpt.Position;

                        string strLab= string.Format(" E {0:f3}\n N {1:f3}",lp.X,lp.Y);
                        // create mtext
                        MText mtxt = new MText();
                        mtxt.SetDatabaseDefaults();
                        mtxt.Attachment = AttachmentPoint.MiddleLeft;
                        mtxt.Location = lp;
                        mtxt.TextHeight = theight;
                        mtxt.Width = 0.0;
                        mtxt.Contents = strLab;
                        mtxt.Layer = "0";
                        mtxt.ColorIndex = 5;
                        mtxt.TransformBy(ucs);                       
                        // add mtext to database and transaction
                        btr.AppendEntity(mtxt);

                        tr.AddNewlyCreatedDBObject(mtxt, true);

                        tr.TransactionManager.QueueForGraphicsFlush();

                    }
                    doc.TransactionManager.FlushGraphics();

                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format(
                    "Error:\n{0}\nTrace:\n{1}", ex.Message, ex.StackTrace));
                }
            }
        }

 Chris, see if this helps

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
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!