I have created a command the sets all the values for our CAD Standards (ie textsize, colours, styles etc) and then executes the Mtext command (I have used Tony T's code for executing the command http://www.caddzone.com/CommandLine.cs) Everything seems work fine, but when the MText command is executed, the Mtext dialog box is not there.
Does anyone know a way around this? Do I need to do a P/Invoke and if so, how do I go about finding the correct method?
Solved! Go to Solution.
Have to set MTEXTED system variable to "." (dot) before
I tested quickly seems working good for me
//added into Examples class public static int Add_Mtext(Point3d corner1, string stylename, double dblheight, Point3d corner2, string strText) { return CommandLine.Command("._MTEXT", corner1, "_ST", stylename, "_H", dblheight, corner2, strText, ""); } public static int Mtext_ED(string strEd) { return CommandLine.Command("._MTEXTED ", strEd); } //added to calling class public static void TryMText() { Examples.Add_Mtext(new Point3d(0, 0, 0), "Standard", 100, new Point3d(1000, 300, 0), @"Blabla1\PBlaBla2"); Examples.Mtext_ED(@"."); }
You may not need to script the MTEXT command to get the desired results. Have a look at InplaceTextEditor.
Example (untested):
[CommandMethod("mymtext")] public void mymtext() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptPointOptions ppo = new PromptPointOptions("Specify first corner: "); PromptPointResult ppr = ed.GetPoint(ppo); Point3d corner1 = ppo.BasePoint = ppr.Value; PromptCornerOptions pco = new PromptCornerOptions("Specify opposite corner: ", corner1); pco.UseDashedLine = false; ppr = ed.GetCorner(pco); Point3d corner2 = ppr.Value; Vector3d vec = corner2 - corner1; using (Transaction t = db.TransactionManager.StartTransaction()) { BlockTableRecord curspace = t.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; MText mt = new MText(); mt.Location = corner1; mt.Width = vec.X; mt.Height = vec.Y; curspace.AppendEntity(mt); t.AddNewlyCreatedDBObject(mt, true); InplaceTextEditor.Invoke(mt, new InplaceTextEditorSettings()); t.Commit(); } }