-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk..Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- namespace Base
- {
- public class Class1
- {
-
- # 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 ptlist = new List();
- 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();
- }
- }
- # endregion
- }
- }
|