OnBnNew(object sender, System.EventArgs e) { string setName; while (true) { int index = 1; setName = string.Format("Set {0}", index); bool found = false; foreach (ObjIdSet tmpSet in m_objIdSets) { if (tmpSet.Name == setName) { found = true; break; } } if (!found) { Snoop.ObjIdSet newSet = new Snoop.ObjIdSet(setName); m_objIdSets.Add(newSet); break; } } Display(); }
OnBnDelete(object sender, System.EventArgs e) { Snoop.ObjIdSet curSet = GetCurrentSet(); if (curSet != null) { m_objIdSets.Remove(curSet); } }
GetCurrentSet() { Debug.Assert((m_lvObjIdSets.SelectedItems.Count > 1) == false); if (m_lvObjIdSets.SelectedItems.Count != 0) { Snoop.ObjIdSet tmpSet = (Snoop.ObjIdSet)m_lvObjIdSets.SelectedItems[0].Tag; return(tmpSet); } return(null); }
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 } }
OnBnSnoop(object sender, System.EventArgs e) { Snoop.ObjIdSet curSet = GetCurrentSet(); if (curSet != null) { using (TransactionHelper trHlp = new TransactionHelper(curSet.Db)) { trHlp.Start(); Snoop.Forms.Database form = new Snoop.Forms.Database(curSet.Db, trHlp); form.ShowDialog(); trHlp.Commit(); } } }
CountHardReferences() { Snoop.ObjIdSet objSet = Snoop.Utils.GetSnoopSet(); if (objSet == null) { return; } int[] countArray = new int[objSet.Set.Count]; if (countArray.Length > 0) { objSet.Db.CountHardReferences(objSet.Set, countArray); } for (int i = 0; i < objSet.Set.Count; i++) { AcadUi.PrintToCmdLine(string.Format("\n{0,-30}: {1:d}", AcadUi.ObjToTypeAndHandleStr(objSet.Set[i]), countArray[i])); } }
Purge() { m_db = Utils.Db.GetCurDwg(); if (m_db == null) { return; } Snoop.ObjIdSet objSet = Snoop.Utils.GetSnoopSet(); if (objSet == null) { return; } // set the purgeableIds to everything selected ObjectIdCollection purgableIds = new ObjectIdCollection(); foreach (ObjectId objId in objSet.Set) { purgableIds.Add(objId); } ObjectIdCollection nonPurgableIds = new ObjectIdCollection(); try { m_db.Purge(purgableIds); // see which ones were non-purgeable by seeing which ones got taken out of the array foreach (ObjectId objId in objSet.Set) { if (!purgableIds.Contains(objId)) { nonPurgableIds.Add(objId); } } using (TransactionHelper trHlp = new TransactionHelper(m_db)) { trHlp.Start(); if (purgableIds.Count == 0) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("No purgable objects"); } else { Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(purgableIds, trHlp); objs.Text = "Purgable objects"; objs.ShowDialog(); } if (nonPurgableIds.Count == 0) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("No non-purgable objects"); } else { Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(nonPurgableIds, trHlp); objs.Text = "Non-purgable objects"; objs.ShowDialog(); } trHlp.Commit(); } } catch (AcRx.Exception e) { AcadUi.PrintToCmdLine(string.Format("\nERROR: {0}", ((AcRx.ErrorStatus)e.ErrorStatus).ToString())); } }