马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Copying (DeepCloning) from one Drawing to another using .NET Here’s how to copy entities from the Model Space of a DWG file hosted inside of AutoCAD to an external DWG file.
- // copy Model Space to external DWG
- // by Fenton Webb, DevTech 14/9/2012
- [CommandMethod("CopySpaceToExtDWG")]
- public static void CopySpaceToExtDWG()
- {
- // get the working database (in AutoCAD)
- Database sourceDb = Application.DocumentManager.MdiActiveDocument.Database;
- try
- {
- // create a new destination database
- using (Database destDb = new Database(true, true))
- {
- // get the model space object ids for both dbs
- ObjectId sourceMsId = SymbolUtilityServices.GetBlockModelSpaceId(sourceDb);
- ObjectId destDbMsId = SymbolUtilityServices.GetBlockModelSpaceId(destDb);
-
- // now create an array of object ids to hold the source objects to copy
- ObjectIdCollection sourceIds = new ObjectIdCollection();
-
- // open the sourceDb ModelSpace (current autocad dwg)
- using (BlockTableRecord ms = sourceMsId.Open(OpenMode.ForRead)
- as BlockTableRecord)
- // loop all the entities and record their ids
- foreach (ObjectId id in ms)
- sourceIds.Add(id);
-
- // next prepare to deepclone the recorded ids to the destdb
- IdMapping mapping = new IdMapping();
- // now clone the objects into the destdb
- sourceDb.WblockCloneObjects(sourceIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
- destDb.SaveAs("c:\\temp\\dwgs\\CopyTest.dwg", DwgVersion.Current);
- }
- }
- catch (System.Exception eXP)
- {
- System.Windows.Forms.MessageBox.Show(eXP.ToString());
- }
- }
|