/// <summary>
    /// Let user select a wall and override one display properties of this wall.
    /// User can see the different display of this wall.
    /// </summary>
    public void DisplayPropertiesWallSample()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplay Properties Wall Sample:\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Database db = Application.DocumentManager.MdiActiveDocument.Database;

        //MaterialUtility.
        TransactionManager tm    = db.TransactionManager;
        Transaction        trans = tm.StartTransaction();
        Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;

        try
        {
            PromptEntityOptions optEnt = new PromptEntityOptions("Select an AEC Wall entity");
            optEnt.SetRejectMessage("Selected entity is NOT an AEC Wall entity, try again...");
            optEnt.AddAllowedClass(typeof(Autodesk.Aec.Arch.DatabaseServices.Wall), false);  // Geo is the base class of AEC entities.

            PromptEntityResult resEnt = ed.GetEntity(optEnt);
            if (resEnt.Status != PromptStatus.OK)
            {
                throw new System.Exception("Selection error - aborting");
            }

            Wall pickedWall = trans.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Wall;

            DisplayRepresentationManager displayManager = new DisplayRepresentationManager(db);
            ObjectIdCollection           ids            = displayManager.GetDisplayRepresentationIdsFromCurrentViewport(RXClass.GetClass(typeof(Wall)));

            ObjectId activeDisplayRepId = ids[0];

            DisplayPropertiesWallPlan wallProperties = new DisplayPropertiesWallPlan();

            wallProperties.SubSetDatabaseDefaults(db);
            wallProperties.SetToStandard(db);
            System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();

            DisplayComponent[] components = wallProperties.GetDisplayComponents(out sc);
            int index = -1;
            for (int i = 0; i < sc.Count; i++)
            {
                string componentName = sc[i];
                //Here, we override the display properties for "shrink wrap" and display it on the screen.
                if (componentName == "Shrink Wrap")
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                throw new System.Exception("Lack of display component.");
            }

            DisplayComponentEntity component = components[index] as DisplayComponentEntity;
            component.IsApplicable  = true;
            component.IsVisible     = true;
            component.ByMaterial    = false;
            component.ColorIndex    = 30;
            component.LinetypeScale = 2;
            component.LineWeight    = LineWeight.LineWeight070;

            ObjectId dispWallId = Override.AddToOverrideExtensionDictionaryAndClose(pickedWall, wallProperties);
            OverrideDisplayProperties overrideProperties = new OverrideDisplayProperties();
            overrideProperties.ViewId            = activeDisplayRepId;
            overrideProperties.DisplayPropertyId = dispWallId;
            pickedWall.Overrides.Add(overrideProperties);

            trans.Commit();
        }
        catch (System.Exception e)
        {
            trans.Abort();
            ed.WriteMessage("\n" + e.Message + "\n");
        }
    }
    /// <summary>
    /// Create a material style and override the display properties of this style.
    /// Use Stylemanager to see the overrided display properties.
    /// </summary>
    public void DisplayPropertiesMaterialSample()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplay Properties for Material Sample:\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Database db = Application.DocumentManager.MdiActiveDocument.Database;

        //MaterialUtility.
        TransactionManager tm    = db.TransactionManager;
        Transaction        trans = tm.StartTransaction();
        Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;

        Autodesk.Aec.DatabaseServices.Dictionary dict = new DictionaryMaterialDefinition(db);

        MaterialDefinition materialDefinition = null;

        try
        {
            string name        = "ACADotNetMaterialDefination";
            string description = "Material def created through .NET API";

            if (!dict.Has(name, trans))
            {
                materialDefinition             = dict.NewEntry() as MaterialDefinition;
                materialDefinition.Description = description;
                dict.AddNewRecord(name, materialDefinition);
                trans.AddNewlyCreatedDBObject(materialDefinition, true);
            }
            else
            {
                materialDefinition = trans.GetObject(dict.GetAt(name), OpenMode.ForWrite) as MaterialDefinition;
            }



            DisplayPropertiesMaterial materialProperties = new DisplayPropertiesMaterial();

            materialProperties.SubSetDatabaseDefaults(db);
            materialProperties.SetToStandard(db);

            ObjectId materialId = AddMaterial("wood");
            materialProperties.SurfaceRenderingMaterialId       = materialId;
            materialProperties.SectionRenderingMaterialId       = materialId;
            materialProperties.SectionedBodyRenderingMaterialId = materialId;
            DisplayComponentHatch displayComponentHatch = new DisplayComponentHatch();

            materialProperties.SurfaceHatch.HatchType   = HatchType.UserDefined;
            materialProperties.SurfaceHatch.PatternName = "NETAPITESTPatternName";
            materialProperties.SurfaceHatch.Angle       = 90.0;

            ObjectId dispMaterialId = Override.AddToOverrideExtensionDictionaryAndClose(materialDefinition, materialProperties);

            DisplayRepresentationManager displayManager = new DisplayRepresentationManager(db);
            ObjectIdCollection           ids            = displayManager.GetDisplayRepresentationIdsFromCurrentViewport(RXObject.GetClass(typeof(MaterialDefinition)));

            ObjectId idActiveDispRep = ids[0];

            OverrideDisplayProperties overrideProperties = new OverrideDisplayProperties();
            overrideProperties.ViewId            = idActiveDispRep;
            overrideProperties.DisplayPropertyId = dispMaterialId;
            materialDefinition.Overrides.Add(overrideProperties);

            trans.Commit();
            ed.WriteMessage("\n" +
                            "One new style for material \"ACADotNetMaterialDefination\"is created and the display properties are overrided.\n" +
                            "Use StyleManager to see the settings."
                            + "\n");
        }
        catch (System.Exception e)
        {
            trans.Abort();
            ed.WriteMessage("\n" + e.Message + "\n");
            return;
        }
    }