staticPolylineacPoly=null;[CommandMethod("AddPlObjEvent")]publicstaticvoidAddPlObjEvent(){// Get the current document and database, and start a transactionusing(TransactionacTrans=ActiveUtil.TransactionManager.StartTransaction()){// Create a closed polylineacPoly=newPolyline();acPoly.SetDatabaseDefaults();acPoly.AddVertexAt(0,newPoint2d(1,1),0,0,0);acPoly.AddVertexAt(1,newPoint2d(1,2),0,0,0);acPoly.AddVertexAt(2,newPoint2d(2,2),0,0,0);acPoly.AddVertexAt(3,newPoint2d(3,3),0,0,0);acPoly.AddVertexAt(4,newPoint2d(3,2),0,0,0);acPoly.Closed=true;// Add the new object to the block table record and the transactionActiveUtil.Database.GetModelSpace(OpenMode.ForWrite).AppendEntity(acPoly);acTrans.AddNewlyCreatedDBObject(acPoly,true);acPoly.Modified+=newEventHandler(acPolyMod);// Save the new object to the databaseacTrans.Commit();}}[CommandMethod("RemovePlObjEvent")]publicstaticvoidRemovePlObjEvent(){if(acPoly!=null){// Get the current document and database, and start a transactionDocumentacDoc=Application.DocumentManager.MdiActiveDocument;DatabaseacCurDb=acDoc.Database;using(TransactionacTrans=acCurDb.TransactionManager.StartTransaction()){// Open the polyline for readacPoly=acTrans.GetObject(acPoly.ObjectId,OpenMode.ForRead)asPolyline;if(acPoly.IsWriteEnabled==false){acPoly.UpgradeOpen();}acPoly.Modified-=newEventHandler(acPolyMod);acPoly=null;}}}publicstaticvoidacPolyMod(objectsenderObj,EventArgsevtArgs){Application.ShowAlertDialog("The area of "+acPoly.ToString()+" is: "+acPoly.Area);}