- 积分
- 2124
- 明经币
- 个
- 注册时间
- 2011-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- namespace Base
- {
- public class Class1
- {
- //模拟CAD的PL命令
- # region mpolyline命令
- [CommandMethod("mpolyline")]
- public static void MyPolyline()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
-
- using(Transaction trans=db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
- Polyline pl1 = new Polyline();
- btr.AppendEntity(pl1);
- trans.AddNewlyCreatedDBObject(pl1, true);
- Point2d ptvetex;
- List<Point2d> ptlist = new List<Point2d>();
- PromptPointOptions ptoptions = new PromptPointOptions("");
- ptoptions.Message = "\n请选择起点:";
- ptoptions.AllowNone = true;
- ptoptions.AllowArbitraryInput = false;
- PromptPointResult result = ed.GetPoint(ptoptions);
-
- int i=0;
- while (result.Status == PromptStatus.OK | result.Status == PromptStatus.Keyword)
- {
- if (result.Status == PromptStatus.OK)
- {
- ptvetex = new Point2d(result.Value.X, result.Value.Y);
- pl1.AddVertexAt(i, ptvetex, 0, 0, 0);
- ptlist.Add(ptvetex);
- pl1.Draw();
- i = i + 1;
- ptoptions.Message = "\n请选择下一点[(W)设置线宽/(C)设置颜色/回车退出:]";
- ptoptions.UseBasePoint = true;
- ptoptions.BasePoint = result.Value;
- ptoptions.Keywords.Add("C");
- ptoptions.Keywords.Add("W");
- result = ed.GetPoint(ptoptions);
-
- }
- if (result.Status == PromptStatus.Keyword)
- {
- if (result.StringResult == "W")
- {
- pl1.LineWeight = LineWeight.LineWeight040;
- }
- else
- {
- pl1.ColorIndex = 2;
- }
- pl1.Draw();
- ptoptions.Message = "\n请选择下一点[(W)设置线宽/(C)设置颜色/回车退出:]";
- ptoptions.AllowNone = true;
- ptoptions.AllowArbitraryInput = false;
- ptoptions.UseBasePoint = true;
- ptoptions.BasePoint = new Point3d(ptlist[i-1].X, ptlist[i-1].Y, 0);
- ptoptions.Keywords.Add("C");
- ptoptions.Keywords.Add("W");
- result = ed.GetPoint(ptoptions);
-
-
- }
- }
- trans.Commit();
- }
- }// end MyPolyline
- # endregion
- }
- }
|
|