Author Topic: Import text-value by picking in a windowsform  (Read 4258 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Re: Import text-value by picking in a windowsform
« Reply #15 on: March 27, 2014, 11:33:01 AM »
Think of me more like a technical adviser suggesting tweaks to improve nozzle efficiency.

Oh, That's perfectly fine.
If it wasn't for people like you, people like me wouldn't learn near as much.  :laugh:
Thanks again!

And just for chuckles, here's my version of the string version (subject to constructive critism of coarse!)   :wink:

Code: [Select]
//select text button.
        private void button2_Click(object sender, EventArgs e)
        {
           label2.Text = PickTextInDrawing.GetTextStringValue();           
        }             

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace DisplayTextValue
{
    class PickTextInDrawing
    {
        public static string GetTextStringValue()
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor editor = document.Editor;
            Database database = HostApplicationServices.WorkingDatabase;
            string TxtVal = "";

            PromptEntityOptions options = new PromptEntityOptions("\nSelect Text Object: < pick > ");
            options.AllowNone = false;
            options.SetRejectMessage("\nMust be DBText. ");
            options.AddAllowedClass(typeof(DBText), false);
           
            Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
            PromptEntityResult selection = editor.GetEntity(options);

            if (selection.Status == PromptStatus.OK)
            {
                using (document.LockDocument())
                {
                    using (Transaction trans = database.TransactionManager.StartTransaction())
                    {
                      DBText text = trans.GetObject(selection.ObjectId, OpenMode.ForRead, false, false) as DBText;
                      TxtVal = text.TextString;
                      trans.Commit();
                    }
                }               
            }
            return TxtVal;
        }

    }
}

Bill
« Last Edit: March 27, 2014, 12:18:45 PM by BillZndl »