这是我测试成功的代码
- Document doc = Env.Document;
- var db = doc.Database;
- var r1 = doc.Editor.GetSelection();
- if (r1.Status != PromptStatus.OK) return;
- ObjectIdCollection oidc = new(r1.Value.GetObjectIds());
- var newdb = new Database(true, true);
- using var tr = newdb.TransactionManager.StartTransaction();
- var bt = tr.GetObject(newdb.BlockTableId, OpenMode.ForRead) as BlockTable;
- IdMapping idm = new();
- db.WblockCloneObjects(oidc, bt![BlockTableRecord.ModelSpace], idm, DuplicateRecordCloning.Replace, false);
- newdb.SaveAs(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\123.dwg",DwgVersion.AC1800);
|