GetSnoopSet() { try { Snoop.ObjIdSet objSet = new Snoop.ObjIdSet("*A"); // TBD: how to deal with named sets? ... later... // select the graphic objects they want PromptSelectionOptions selOpts = new PromptSelectionOptions(); selOpts.MessageForAdding = "Select graphical objects for test (or RETURN for none)"; Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptSelectionResult res = ed.GetSelection(selOpts); if (res.Status == PromptStatus.OK) { foreach (ObjectId objId in res.Value.GetObjectIds()) // set these as the original, let dialog add the rest { objSet.AddToSet(objId); } } else if (res.Status == PromptStatus.Error) { ; // empty selection set } else { return(null); } Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Select non-graphical objects by browsing, right-click on item, choose \"Add to Snoop Set\"."); using (TransactionHelper trHlp = new TransactionHelper(MgdDbg.Utils.Db.GetCurDwg())) { trHlp.Start(); Snoop.Forms.Database form = new Snoop.Forms.Database(trHlp.Database, trHlp); // temporarily hook up the snoop set to the snoop browse dialogs. m_snoopObjSet = objSet; if (form.ShowDialog() == DialogResult.OK) { trHlp.Commit(); return(objSet); } else { trHlp.Abort(); return(null); } } } finally { m_snoopObjSet = null; // reset to null for next invocation } }
WblockCloneObjects() { try { m_db = Utils.Db.GetCurDwg(); if (m_db == null) { return; } using (TransactionHelper trHlpr = new TransactionHelper()) { trHlpr.Start(); /// get the object to clone Objects objs = new Objects(trHlpr); if (objs.ShowDialog() != DialogResult.OK) { trHlpr.Abort(); return; } DBObject objToClone = trHlpr.Transaction.GetObject(objs.ObjectId, OpenMode.ForRead); if (objToClone is DBDictionary) { throw new System.Exception("Please select a record in a dictionary"); } AcadApp.Document activeDoc = AcadApp.Application.DocumentManager.MdiActiveDocument; /// get cloning options... /// //String message = "\nDuplicate Record Cloning Options:"; //Array enums = Enum.GetValues(typeof(DuplicateRecordCloning)); //foreach (int option in enums) { // message += string.Format("\n{0} = {1}", // option, // Enum.GetName(typeof(DuplicateRecordCloning), option)); //} //PromptIntegerOptions prOpts = new PromptIntegerOptions(message); //prOpts.LowerLimit = 0; //prOpts.UpperLimit = enums.Length; //Editor ed = activeDoc.Editor; //PromptIntegerResult prRes = ed.GetInteger(prOpts); //if (prRes.Status != PromptStatus.OK) // return; //DuplicateRecordCloning drc = (DuplicateRecordCloning)prRes.Value; //if (drc == DuplicateRecordCloning.NotApplicable || // drc == DuplicateRecordCloning.RefMangleName) { // ed.WriteMessage("Invalid Input"); // return; //} /// .... or not DuplicateRecordCloning drc = DuplicateRecordCloning.Ignore; if (objToClone.OwnerId == ObjectId.Null) /// object to clone is a root object, can't clone { return; } /// get the destination db Documents docs = new Documents(); docs.Text = "Destination database"; if (docs.ShowDialog() != DialogResult.OK) { return; } Database dbSrc = activeDoc.Database; Database dbDest = docs.Document.Database; if (dbDest == dbSrc) { throw new System.Exception("Please pick a destination database other than the source"); } /// find out parent dictionary ObjectId owningDictId = objToClone.OwnerId; DBDictionary owningDictSrc = trHlpr.Transaction.GetObject(owningDictId, OpenMode.ForRead) as DBDictionary; /// might be nested Stack owningDictNames = new Stack(); while (owningDictSrc.OwnerId != ObjectId.Null) { owningDictSrc = trHlpr.Transaction.GetObject(owningDictSrc.OwnerId, OpenMode.ForRead) as DBDictionary; String owningDictName = owningDictSrc.NameAt(owningDictId); owningDictNames.Push(owningDictName); owningDictId = owningDictSrc.ObjectId; } /// check if parent dictionary exists in dest. DBDictionary owningDictDest = null; using (Transaction trDest = dbDest.TransactionManager.StartTransaction()) { AcadApp.Application.DocumentManager.GetDocument(dbDest).LockDocument(); DBDictionary parentDictDest = trDest.GetObject(dbDest.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary; String owningDictName = owningDictNames.Peek().ToString(); if (parentDictDest.Contains(owningDictName)) { while (owningDictNames.Count != 0) { owningDictName = owningDictNames.Pop().ToString(); owningDictDest = trDest.GetObject(parentDictDest.GetAt(owningDictName), OpenMode.ForRead) as DBDictionary; parentDictDest = owningDictDest; } } else { /// dest doesnt have same structure , create it while (owningDictNames.Count != 0) { owningDictName = owningDictNames.Pop().ToString(); parentDictDest.UpgradeOpen(); owningDictDest = new DBDictionary(); parentDictDest.SetAt(owningDictName, owningDictDest); trDest.AddNewlyCreatedDBObject(owningDictDest, true); parentDictDest = owningDictDest; } } trDest.Commit(); } /// clone the objects over ObjectIdCollection objIds = new ObjectIdCollection(); objIds.Add(objToClone.ObjectId); IdMapping idMap = new IdMapping(); idMap.DestinationDatabase = dbDest; m_db.WblockCloneObjects(objIds, owningDictDest.ObjectId, idMap, drc, false); trHlpr.Commit(); } } catch (AcRx.Exception ex) { if (ex.ErrorStatus == AcRx.ErrorStatus.FileNotFound) { MessageBox.Show("No documents found in current session"); } else { MessageBox.Show(ex.Message); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }