- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- namespace UCStext
- {
- public class Class1
- {
- [CommandMethod("aa")]
- public void aa()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Application.DocumentManager.MdiActiveDocument;
- PromptPointOptions op = new PromptPointOptions("insert point:");
- PromptPointResult opres = doc.Editor.GetPoint(op);
- Point3d pt = opres.Value;
- Matrix3d mt = doc.Editor.CurrentUserCoordinateSystem;
- DBText ent = new DBText();
- ent.TextString = " 我是中国人";
- ent.Position = pt;
- ent.TransformBy(mt);
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btrec = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- btrec.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- }
- }
- }
终于解决了 |