下面是个例子
Here is a sample code that uses the "Entity.JoinEntity" method :
 - [CommandMethod("joinPline")]
- static public void joinPolylines()
- {
- PromptEntityResult pEntrs;
- PromptEntityOptions peo1 = new PromptEntityOptions("\nSelect source polyline : ");
- peo1.SetRejectMessage("\nInvalid selection...");
- peo1.AddAllowedClass(typeof(Polyline), true);
- peo1.AddAllowedClass(typeof(Polyline2d), true);
- peo1.AddAllowedClass(typeof(Polyline3d), true);
- pEntrs = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(peo1);
- if (PromptStatus.OK != pEntrs.Status)
- return;
- ObjectId srcId = pEntrs.ObjectId;
- PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect polyline to join : ");
- peo2.SetRejectMessage("\nInvalid selection...");
- peo2.AddAllowedClass(typeof(Polyline), true);
- peo2.AddAllowedClass(typeof(Polyline2d), true);
- peo2.AddAllowedClass(typeof(Polyline3d), true);
- pEntrs = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(peo2);
- if (PromptStatus.OK != pEntrs.Status)
- return;
- ObjectId joinId = pEntrs.ObjectId;
- Transaction trans = null;
- try
- {
- using (trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
- {
- Entity srcPLine = trans.GetObject(srcId, OpenMode.ForRead) as Entity;
- Entity addPLine = trans.GetObject(joinId, OpenMode.ForRead) as Entity;
- srcPLine.UpgradeOpen();
- srcPLine.JoinEntity(addPLine);
- addPLine.UpgradeOpen();
- addPLine.Erase();
- trans.Commit();
- }
- }
- catch (System.Exception ex)
- {
- Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
- }
- }
|