How to copy a part of polyline

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,everyone,
I am a beginer of AutoCAD.net. My question is how to create a new polyline which vertex is from a old polyline.
My code seems have a copy a polyline in debug, but I can't find the new polyline in AutoCAD,why?
The code is below:
[CommandMethod("CopyPartPolyline")]
public void CopyPartPolyline()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Polyline pline = selectOnePolyline(acCurDb); //prompt user to select a polyline from screen
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;
// Create a lightweight polyline
Polyline acPoly = new Polyline();
acPoly.SetDatabaseDefaults();
for (int i = 0; i < pline.NumberOfVertices; i=i+2)
{
double x = pline.GetPoint2dAt(i).X; double y = pline.GetPoint2dAt(i).Y;
acPoly.AddVertexAt(i/2, new Point2d(x, y), 0, 0, 0);
}
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
acPoly.Closed = true;
acTrans.Commit();
}