How to Crate Mtext and visible with the cursor, & exit when escape

How to Crate Mtext and visible with the cursor, & exit when escape

kite15
Advocate Advocate
756 Views
4 Replies
Message 1 of 5

How to Crate Mtext and visible with the cursor, & exit when escape

kite15
Advocate
Advocate

Hi,

I am trying to create a tool by which can provide Mtext by clicking a button.

1. Mtext contain will visible [jig] with the cursor.

2. after locating a point its can not exit from the command will asking for another point with compiled mtext contain [contain changed] - loop.

3. when press the escape button it will exit from the operation.

 

created Mtext and can provide in the AutoCAD interface. whereas the operation exit after one operation. jig creation is new for me

 

Please help!

0 Likes
Accepted solutions (1)
757 Views
4 Replies
Replies (4)
Message 2 of 5

ActivistInvestor
Mentor
Mentor

You should post the code you have tried, and then it may be easier to understand what you're trying to do.

 


@kite15 wrote:

Hi,

I am trying to create a tool by which can provide Mtext by clicking a button.

1. Mtext contain will visible [jig] with the cursor.

2. after locating a point its can not exit from the command will asking for another point with compiled mtext contain [contain changed] - loop.

3. when press the escape button it will exit from the operation.

 

created Mtext and can provide in the AutoCAD interface. whereas the operation exit after one operation. jig creation is new for me

 

Please help!


 

0 Likes
Message 3 of 5

kite15
Advocate
Advocate

Please see the snap for the code [Mtexts]

 

0 Likes
Message 4 of 5

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Here's a simple example using a command you can adapt to your dialog.

 

    public class Commands
    {
        [CommandMethod("MIMT")]
        public void MultiInsertMText()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                while (true)
                {
                    using (var mtext = new MText())
                    {
                        mtext.Contents = "Drag me !";
                        mtext.Height = db.Textsize;
                        mtext.Rotation = Math.PI / 2.0;
                        mtext.Attachment = AttachmentPoint.MiddleCenter;
                        mtext.TextStyleId = db.Textstyle;
                        curSpace.AppendEntity(mtext);
                        tr.AddNewlyCreatedDBObject(mtext, true);
                        MTextJig jig = new MTextJig(mtext);
                        var result = ed.Drag(jig);
                        if (result.Status != PromptStatus.OK)
                        {
                            mtext.Erase();
                            break;
                        }
                        db.TransactionManager.QueueForGraphicsFlush();

                    }
                }
                tr.Commit();
            }
        }
    }

    class MTextJig : EntityJig
    {
        MText mtext;
        Point3d basePt, dragPt;

        public MTextJig(MText mtext) : base(mtext)
        {
            this.mtext = mtext;
            basePt = mtext.Location;
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            var options = new JigPromptPointOptions("\nInsertion point: ");
            options.BasePoint = basePt;
            options.UseBasePoint = true;
            options.UserInputControls =
                UserInputControls.Accept3dCoordinates |
                UserInputControls.NullResponseAccepted | // allows Enter to break the loop
                UserInputControls.UseBasePointElevation;
            var result = prompts.AcquirePoint(options);
            if (result.Value.IsEqualTo(dragPt))
                return SamplerStatus.NoChange;
            dragPt = result.Value;
            return SamplerStatus.OK;
        }

        protected override bool Update()
        {
            mtext.Location = dragPt;
            return true;
        }
    }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

kite15
Advocate
Advocate

Hi _gile,

 

This is perfect another one, thank you for your continuous help awesome Smiley Happy

0 Likes