- 积分
- 526
- 明经币
- 个
- 注册时间
- 2006-10-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2010-12-28 13:26:20
|
显示全部楼层
代码如下- struct text
- {
- public double position;
- public String content;
- }
- [CommandMethod("TTT")]
- public void ttt()
- {
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Transaction tran=db.TransactionManager.StartTransaction();
- Entity entity = null;
- MText mt=new MText();
- DBText dt = new DBText();
- String cs = "";
- List<text> ltext = new List<text>();
-
- PromptSelectionOptions selops = new PromptSelectionOptions(); // 建立选择的过滤器内容
- TypedValue[] filList = new TypedValue[4];
- filList[0] = new TypedValue((int)DxfCode.Operator, "<or");
- filList[1] = new TypedValue((int)DxfCode.Start, "Mtext");
- filList[2] = new TypedValue((int)DxfCode.Start, "text");
- filList[3] = new TypedValue((int)DxfCode.Operator, "or>");
- SelectionFilter filter = new SelectionFilter(filList);
- PromptSelectionResult ents = ed.GetSelection(selops,filter);
- if (ents.Status == PromptStatus.OK)
- {
- SelectionSet SS = ents.Value;
- foreach (ObjectId id in SS.GetObjectIds())
- {
- entity = (Entity)tran.GetObject(id, OpenMode.ForRead);
- if (entity.GetType() == typeof(MText))
- {
- mt = (MText)entity;
- ltext.Add(new text() { position = mt.Location.Y, content = mt.Contents.ToString().Replace("\\P"," ")});
- }
- if (entity.GetType() == typeof(DBText))
- {
- dt = (DBText)entity;
- ltext.Add(new text() { position = dt.Position.Y, content = dt.TextString });
- }
- }
- }
- ltext.Sort(new Comparison<text>((t1, t2) => t1.position > t2.position ? 1 : 0));
- //ltext.Sort(n =>n.position);
- foreach (text t in ltext)
- {
- cs=cs+t.content+"\n";
- }
- cs = cs.TrimEnd('\n');
- Clipboard.SetDataObject(cs);
- tran.Commit();
- tran.Dispose();
- }
复制代码 |
|