Mtext не работает в моем коде
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Windows.ToolPalette; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyApp { public class Attributes { [CommandMethod("NLTAG")] public void ListAttributes() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; Transaction tr = db.TransactionManager.StartTransaction(); PromptPointResult ppr; PromptPointOptions ppo = new PromptPointOptions(""); // Start the transaction try { // Build a filter list so that only // block references are selected TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.Start, "INSERT") }; SelectionFilter filter = new SelectionFilter(filList); PromptSelectionOptions opts = new PromptSelectionOptions(); opts.MessageForAdding = "Select block references: "; PromptSelectionResult res = ed.GetSelection(opts, filter); //get the coordinates from user ppo.Message = "\n Select the place for print output:"; ppr = acDoc.Editor.GetPoint(ppo); Point3d ptstart = ppr.Value; ppo.UseBasePoint = true; ppo.BasePoint = ptstart; if (ppr.Status == PromptStatus.Cancel) return; double x = ptstart.X; double y = ptstart.Y; double z = 0; // Do nothing if selection is unsuccessful if (res.Status != PromptStatus.OK) return; SelectionSet selSet = res.Value; ObjectId[] idArray = selSet.GetObjectIds(); foreach (ObjectId blkId in idArray) { BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead); //ed.WriteMessage( "\nBlock: " + btr.Name ); btr.Dispose(); AttributeCollection attCol = blkRef.AttributeCollection; foreach (ObjectId objId in attCol) { MText mtext = new MText(); mtext.Width = 6; mtext.Location = new Point3d(x, y, z); AttributeReference attRef = (AttributeReference)tr.GetObject(objId, OpenMode.ForRead); string str = ("\n attribute is :" + attRef.TextString); ed.WriteMessage(str); var entity = tr.GetObject(objId, OpenMode.ForRead); mtext.Contents = "\n" + attRef; attCol.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(mtext, true); } } tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(("Exception: " + ex.Message)); } finally { tr.Dispose(); } } } }
Что я уже пробовал:
Я пытаюсь распечатать свой вывод в моем файле dwg, но mtext не работает, вывод не отображается в файле dwg.
@j@y123
Вывод корректен в командной строке, но mtext не отображается в dwg