Example #1
0
 ContextMenuClick_ShowSnoopObjSet(object sender, System.EventArgs e)
 {
     if (Snoop.Utils.CurrentSnoopSet != null)
     {
         Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(Snoop.Utils.CurrentSnoopSet.Set, m_trans);
         form.Text = "Snoop Object Set";
         form.ShowDialog();
     }
 }
Example #2
0
        AttachXref()
        {
            m_db = Utils.Db.GetCurDwg();
            if (m_db == null)
            {
                return;
            }

            string fileName = Utils.Dialog.OpenFileDialog(".dwg", "Choose dwg to attach as Xref", "Dwg files (*.dwg)|*.dwg");

            if (fileName.Length == 0)
            {
                return;
            }
            string blockName = System.IO.Path.GetFileNameWithoutExtension(fileName);

            if (blockName.Length == 0)
            {
                return;
            }
            if (blockName.ToLower() == System.IO.Path.GetFileNameWithoutExtension(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name).ToLower())
            {
                MessageBox.Show("External file name used could lead to a circular reference.", "MgdDbg", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ObjectId objId = m_db.AttachXref(fileName, blockName);

            using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                trHlp.Start();

                BlockTableRecord btr    = (BlockTableRecord)trHlp.Transaction.GetObject(objId, OpenMode.ForRead);
                Database         xrefDb = btr.GetXrefDatabase(true);

                BlockTable blkTbl = (BlockTable)trHlp.Transaction.GetObject(m_db.BlockTableId, OpenMode.ForRead);

                ObjectIdCollection blkRecIds = new ObjectIdCollection();
                blkRecIds.Add(btr.ObjectId);

                foreach (ObjectId tblRecId in blkTbl)
                {
                    BlockTableRecord blkRec = (BlockTableRecord)trHlp.Transaction.GetObject(tblRecId, OpenMode.ForRead);
                    if (blkRec.Database == xrefDb)
                    {
                        blkRecIds.Add(tblRecId);
                    }
                }

                Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(blkRecIds, trHlp);
                form.Text = "Xref Block Table Records";
                form.ShowDialog();
                trHlp.Commit();
            }
        }
Example #3
0
        DrillDown()
        {
            if ((m_val != null) && (m_val.Count > 0))
            {
                using (TransactionHelper trHlp = new TransactionHelper(m_val[0].Database)) {
                    trHlp.Start();

                    Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(m_val, trHlp);
                    form.ShowDialog();

                    trHlp.Commit();
                }
            }
        }
Example #4
0
        OnBnShow(object sender, System.EventArgs e)
        {
            Snoop.ObjIdSet curSet = GetCurrentSet();
            if (curSet != null)
            {
                using (TransactionHelper trHlp = new TransactionHelper(curSet.Db)) {
                    trHlp.Start();

                    Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(curSet.Set, trHlp);
                    form.ShowDialog();

                    trHlp.Commit();
                }
            }
        }
Example #5
0
        DrillDown()
        {
            if (m_val.Count > 0)
            {
                Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection objIds = new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection(m_val.GetObjectIds());
                using (TransactionHelper trHlp = new TransactionHelper(objIds[0].Database)) {
                    trHlp.Start();

                    Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(objIds, trHlp);
                    form.ShowDialog();

                    trHlp.Commit();
                }
            }
        }
Example #6
0
        DrillDown()
        {
            if (m_val.IsNull == false)
            {
                Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection objIds = new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
                objIds.Add(m_val);

                using (TransactionHelper trHlp = new TransactionHelper(m_val.Database)) {
                    trHlp.Start();

                    Snoop.Forms.DBObjects form = new Snoop.Forms.DBObjects(objIds, trHlp);
                    form.ShowDialog();

                    trHlp.Commit();
                }
            }
        }
Example #7
0
        InsertBlock()
        {
            m_db = Utils.Db.GetCurDwg();
            if (m_db == null)
            {
                return;
            }

            string dwgName = Utils.Dialog.OpenFileDialog(".dwg", "Choose dwg to insert from", "Dwg files (*.dwg)|*.dwg");

            if (dwgName.Length == 0)
            {
                return;
            }

            Database extDb = new Database(false, true);

            extDb.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, null);

            if (extDb == null)
            {
                return;
            }

            // TBD: should allow user to select source block and name the destination block

            ObjectId objId = m_db.Insert("*Model_Space", "MgdDbg_InsertedBlock2", extDb, true);

            using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                trHlp.Start();

                ObjectIdCollection objIds = new ObjectIdCollection();
                objIds.Add(objId);

                Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(objIds, trHlp);
                objs.Text = "Inserted Block";
                objs.ShowDialog();

                trHlp.Commit();
            }
        }
Example #8
0
        SnoopEntity()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptSelectionResult res = ed.GetSelection();

            if (res.Status != PromptStatus.OK)
            {
                return;
            }

            ObjectIdCollection selSet = new ObjectIdCollection(res.Value.GetObjectIds());

            using (TransactionHelper trHlp = new TransactionHelper()) {
                trHlp.Start();

                Snoop.Forms.DBObjects dbox = new Snoop.Forms.DBObjects(selSet, trHlp);
                dbox.Text = "Selected Entities";
                AcadApp.ShowModalDialog(dbox);

                trHlp.Commit();
            }
        }
Example #9
0
        InsertInBlockTable()
        {
            m_db = Utils.Db.GetCurDwg();
            if (m_db == null)
            {
                return;
            }

            string dwgName = Utils.Dialog.OpenFileDialog(".dwg", "Choose dwg to insert from", "Dwg files (*.dwg)|*.dwg");

            if (dwgName.Length == 0)
            {
                return;
            }

            try {
                Database extDb = new Database(false, true);
                extDb.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, null);

                ObjectId objId = m_db.Insert("MgdDbg_InsertedBlock", extDb, true);     // TBD: should allow user to name the destination block
                using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                    trHlp.Start();

                    ObjectIdCollection objIds = new ObjectIdCollection();
                    objIds.Add(objId);

                    Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(objIds, trHlp);
                    objs.Text = "Inserted Block";
                    objs.ShowDialog();

                    trHlp.Commit();
                }
            }
            catch (AcRx.Exception e) {
                AcadUi.PrintToCmdLine(string.Format("\nERROR: {0}", ((AcRx.ErrorStatus)e.ErrorStatus).ToString()));
            }
        }
Example #10
0
        OverlayXref()
        {
            m_db = Utils.Db.GetCurDwg();
            if (m_db == null)
            {
                return;
            }

            string fileName = Utils.Dialog.OpenFileDialog(".dwg", "Choose dwg to overlay as Xref", "Dwg files (*.dwg)|*.dwg");

            if (fileName.Length == 0)
            {
                return;
            }

            string blockName = System.IO.Path.GetFileNameWithoutExtension(fileName);

            if (blockName.Length == 0)
            {
                return;
            }

            ObjectId objId = m_db.OverlayXref(fileName, blockName);

            using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                trHlp.Start();

                ObjectIdCollection objIds = new ObjectIdCollection();
                objIds.Add(objId);

                Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(objIds, trHlp);
                objs.Text = "Xrefd Block";
                objs.ShowDialog();

                trHlp.Commit();
            }
        }
Example #11
0
        SnoopEntityByHandle()
        {
            ObjectId           id     = ObjectId.Null;
            ObjectIdCollection selSet = new ObjectIdCollection();

            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptStringOptions options = new PromptStringOptions("Handle of database object");

            String str = ed.GetString(options).StringResult;

            if (str != String.Empty)
            {
                Handle h = Utils.Db.StringToHandle(str);

                try {
                    id = Utils.Db.HandleToObjectId(db, h);

                    selSet.Add(id);

                    using (TransactionHelper trHlp = new TransactionHelper()) {
                        trHlp.Start();

                        Snoop.Forms.DBObjects dbox = new Snoop.Forms.DBObjects(selSet, trHlp);
                        dbox.Text = "Selected Entities";
                        AcadApp.ShowModalDialog(dbox);

                        trHlp.Commit();
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception x) {
                    AcadUi.PrintToCmdLine(string.Format("\nERROR: {0}", ((ErrorStatus)x.ErrorStatus).ToString()));
                }
            }
        }
Example #12
0
        SnoopNestedEntity()
        {
            Editor             ed     = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectIdCollection selSet = new ObjectIdCollection();

            while (true)
            {
                PromptNestedEntityOptions prOptNent = new PromptNestedEntityOptions("\nSelect nested entities or: ");
                prOptNent.AppendKeywordsToMessage = true;
                prOptNent.Keywords.Add("Done");

                PromptNestedEntityResult res = ed.GetNestedEntity(prOptNent);
                if (res.Status == PromptStatus.OK)
                {
                    selSet.Add(res.ObjectId);
                }
                else if (res.Status == PromptStatus.Keyword)
                {
                    break;
                }
                else
                {
                    return;
                }
            }

            using (TransactionHelper trHlp = new TransactionHelper()) {
                trHlp.Start();

                Snoop.Forms.DBObjects dbox = new Snoop.Forms.DBObjects(selSet, trHlp);
                dbox.Text = "Selected Entities";
                AcadApp.ShowModalDialog(dbox);

                trHlp.Commit();
            }
        }
Example #13
0
        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()));
            }
        }
Example #14
0
        DeepClone()
        {
            m_db = Utils.Db.GetCurDwg();
            if (m_db == null)
            {
                return;
            }

            ObjectIdCollection selSet = null;

            if (Utils.AcadUi.GetSelSetFromUser(out selSet) == false)
            {
                return;
            }
            if (selSet.Count == 0)
            {
                return;
            }


            ObjectId  ownerId = new ObjectId();
            IdMapping idMap   = new IdMapping();

            /// check to make sure the objects all have same owner
            /// if not set up as many objIdCollections
            Hashtable ownerIdMap = new Hashtable();

            using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                trHlp.Start();

                foreach (ObjectId tempId in selSet)
                {
                    DBObject tempObj = trHlp.Transaction.GetObject(tempId, OpenMode.ForRead);

                    if (ownerIdMap.ContainsKey(tempObj.OwnerId))
                    {
                        ObjectIdCollection objIds = ownerIdMap[tempObj.OwnerId] as ObjectIdCollection;
                        objIds.Add(tempId);
                    }
                    else
                    {
                        /// if a new owner if found, stuff it in map
                        ObjectIdCollection objIds = new ObjectIdCollection();
                        objIds.Add(tempId);
                        ownerIdMap.Add(tempObj.OwnerId, objIds);
                    }
                }
                /// make the model space the owner by default
                BlockTable blkTbl = (BlockTable)trHlp.Transaction.GetObject(m_db.BlockTableId, OpenMode.ForRead);
                ownerId = blkTbl["*MODEL_SPACE"];

                trHlp.Commit();
            }

            ICollection keys         = ownerIdMap.Keys;
            int         keyCount     = ownerIdMap.Keys.Count;
            int         i            = 0;
            bool        deferXlation = true;


            using (TransactionHelper trHlp = new TransactionHelper(m_db)) {
                trHlp.Start();

                /// if objects to be cloned have different owners
                /// DeepCloneObjects should be called with
                /// deferXlation set to true for all except last time
                foreach (object key in keys)
                {
                    i++;
                    if (i == keyCount)
                    {
                        deferXlation = false;
                    }
                    ObjectIdCollection objectIds = ownerIdMap[key] as ObjectIdCollection;
                    m_db.DeepCloneObjects(objectIds, ownerId, idMap, deferXlation);

                    Snoop.Forms.DBObjects objs = new Snoop.Forms.DBObjects(objectIds, trHlp);
                    objs.Text = "Deep cloned objects";
                    objs.ShowDialog();
                }
                trHlp.Commit();
            }
        }