Esempio n. 1
0
        void RecursiveReferencesToOfSeletedObject()
        {
            //
            // Transaction processing
            //
            Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;
            Database           db    = Application.DocumentManager.MdiActiveDocument.Database;
            TransactionManager tm    = db.TransactionManager;
            Transaction        trans = tm.StartTransaction();

            try
            {
                PromptEntityOptions entopts = new PromptEntityOptions("Select an Aec Entity ");
                entopts.SetRejectMessage("Must select an Aec Entity, please!");
                entopts.AddAllowedClass(typeof(Autodesk.Aec.DatabaseServices.Entity), false);
                PromptEntityResult ent = null;
                try
                {
                    ent = ed.GetEntity(entopts);
                }
                catch
                {
                    ed.WriteMessage("You did not select a valid entity");
                    return;
                }

                if (ent.Status == PromptStatus.OK)
                {
                    ObjectId entId = ent.ObjectId;

                    Autodesk.Aec.DatabaseServices.Entity aecent = tm.GetObject(entId, OpenMode.ForRead, false) as Autodesk.Aec.DatabaseServices.Entity;

                    DBObjectRelationshipManager    mgr    = new DBObjectRelationshipManager();
                    DBObjectRelationshipCollection refsTo = mgr.GetReferencesToThisObjectRecursive(aecent, 0, false);

                    ed.WriteMessage("\n\n");
                    foreach (DBObjectRelationship relTo in refsTo)
                    {
                        ed.WriteMessage("Ent ID = " + entId.ToString() + "  " + entId.ObjectClass.Name.ToString() + " is referenced recursively by: " + relTo.Id.ToString() + "("
                                        + relTo.Id.ObjectClass.Name + ")" + ", whose relationship type is "
                                        + relTo.RelationshipType.ToString() + "\n");
                    }
                }

                trans.Commit();
            }
            catch (System.Exception e)
            {
                trans.Abort();
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }
Esempio n. 2
0
    ////////////////////////////
    //// Display Configuration
    ////////////////////////////

    private void DisplayConfigs()
    {
        //' access the display system from the database object

        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        try
        {
            // Access the display system from the document object
            DictionaryDisplayConfiguration dictDisplayConfigs = new DictionaryDisplayConfiguration(db);

            // The total number of display configurations registered.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configs:\n");

            // List them
            foreach (ObjectId dcId in dictDisplayConfigs.Records)
            {
                DisplayConfiguration dc = trans.GetObject(dcId, OpenMode.ForWrite) as DisplayConfiguration;
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Name : " + dc.Name + "\n" +
                                                                                  "Description :  " + dc.Description + "\n");
            }

            // Add a new config with the name "MyConfig" with a description in it.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's add a new DisplayConfiguration:\n");
            DisplayConfiguration displayconfig = new DisplayConfiguration();
            displayconfig.Description = "This is MyConfig";
            if (!dictDisplayConfigs.Has("MyConfig", trans))
            {
                dictDisplayConfigs.AddNewRecord("MyConfig", displayconfig);
                trans.AddNewlyCreatedDBObject(displayconfig, true);
            }

            // Add another one "FORUSE1"
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(displayconfig.Name + " : " + displayconfig.Description + "\n");
            DisplayConfiguration displayconfig1 = new DisplayConfiguration();
            displayconfig1.Description = "This is for use";
            if (!dictDisplayConfigs.Has("FORUSE1", trans))
            {
                dictDisplayConfigs.AddNewRecord("FORUSE1", displayconfig1);
                trans.AddNewlyCreatedDBObject(displayconfig1, true);
            }

            //    rename MyConfig to a new name MyNewConfigureXxx
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's rename this new DisplayConfiguration:\n");
            string newName = GetNewName();
            dictDisplayConfigs.Rename("MyConfig", newName, trans);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("After Renamed:\nName: " + displayconfig.Name + "\nDescription: " + displayconfig.Description + "\n");


            //    report the total number of display config again.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configurations now.\n");

            //    the ObjectId of the new disp config?
            ObjectId nid = dictDisplayConfigs.GetAt(newName);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The current ObjectId for new display configuration is:" + nid.ToString() + "\n");

            //    the current active config?
            DisplayRepresentationManager drm      = new DisplayRepresentationManager(db);
            ObjectId             currentDisConfId = drm.DisplayConfigurationIdForCurrentViewport;
            DisplayConfiguration currentDisConf   = trans.GetObject(currentDisConfId, OpenMode.ForRead) as DisplayConfiguration;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The Current DisplayConfiguration is " + currentDisConf.Name + "\n");
            ListDisplayConfig(currentDisConf);

            //    create a new disp config with more detailed information.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Let's create a new DisplayConfiguration for detail:\n");
            DisplayConfiguration newDc = CreateDisplayConfig();

            //    print it out
            ListDisplayConfig(newDc);

            trans.Commit();
        }
        catch (System.Exception e)
        {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Exception: " + e.Message + "\n");
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
    }