/// <summary>
/// 多线段反向
/// </summary>
/// <returns>无返回值</returns>
[CommandMethod("SetPolyReverse")]
public void SetPolyReverse()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
Polyline pl = new Polyline();
PromptEntityOptions opt = new PromptEntityOptions("请选择目标线: ");
opt.SetRejectMessage("您选择的不是多线段!");
opt.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult optRes = ed.GetEntity(opt);
if (optRes.Status == PromptStatus.OK)
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
// 获取选择的多线段
pl = (Polyline)trans.GetObject(optRes.ObjectId, OpenMode.ForWrite);
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Polyline pl2 = new Polyline();
btr.AppendEntity(pl2);
trans.AddNewlyCreatedDBObject(pl2, true);
int count = Convert.ToInt32(pl.EndParam);
Point2dCollection ptcoll = new Point2dCollection();
DoubleCollection bulges = new DoubleCollection();
for (int i = 0; i <= count; i++)
{
ptcoll.Add(pl.GetPoint2dAt(i));
bulges.Add(pl.GetBulgeAt(i));
}
for (int i = 0; i <= count; i++)
{
pl2.AddVertexAt(i, ptcoll[count - i], 0, 0, 0);
}
for (int i = 0; i <= count - 1; i++)
{
pl2.SetBulgeAt(i, -bulges[count - i - 1]);
}
int ptsNum = pl2.NumberOfVertices;
pl2.Draw();
pl.Erase();
trans.Commit();
docLock.Dispose();
}
}
}