/// <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"); } }
//////////////////////////// //// Display Props //// list all the disp reps for the door for the current view port //////////////////////////// private void DisplayProps() { Database db = Application.DocumentManager.MdiActiveDocument.Database; TransactionManager tm = db.TransactionManager; Transaction trans = db.TransactionManager.StartTransaction(); BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); DictionaryDisplaySet dds = new DictionaryDisplaySet(db, false); try { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptEntityOptions optEnt = new PromptEntityOptions("Select an AEC door entity"); optEnt.SetRejectMessage("Selected entity is NOT an AEC door entity, try again..."); optEnt.AddAllowedClass(typeof(Autodesk.Aec.Arch.DatabaseServices.Door), false); // Geo is the base class of AEC entities. PromptEntityResult resEnt = ed.GetEntity(optEnt); if (resEnt.Status != PromptStatus.OK) { ed.WriteMessage("Selection error - aborting" + "\n"); return; } Autodesk.Aec.Arch.DatabaseServices.Door door = trans.GetObject(resEnt.ObjectId, OpenMode.ForRead) as Door; ed.WriteMessage("You have selected an " + door.GetRXClass().Name + "\n"); // get its style Autodesk.Aec.Arch.DatabaseServices.DoorStyle doorstyle = trans.GetObject(door.StyleId, OpenMode.ForRead) as DoorStyle; ObjectId doorId = door.ObjectId; DisplayRepresentationManager drm = new DisplayRepresentationManager(db); ObjectIdCollection ids = drm.GetDisplayRepresentationIdsFromCurrentViewport(door.GetRXClass()); DisplayRepresentation dr = null; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n"); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Get all the Display Representations work with the door for current view port\n"); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n"); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("door disp rep count = " + ids.Count + "\n"); foreach (ObjectId id in ids) { dr = trans.GetObject(id, OpenMode.ForRead) as DisplayRepresentation; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Representation Name: " + dr.Name + " Display Name: " + dr.DisplayName + "\n"); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Representation Name: " + dr.Name + "Display Name" + dr.DisplayName + "\n"); DisplayProperties dps = null; RXClass rcProps = dr.DisplayPropertiesClass; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Props Class: " + rcProps.Name + "\n"); // find override at instance level. ObjectId overId = dr.FindDisplayPropertiesOverride(door); if (overId != ObjectId.Null) { dps = trans.GetObject(overId, OpenMode.ForRead) as DisplayProperties; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Element override Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n"); continue; } ObjectId overstyleId = dr.FindDisplayPropertiesOverride(doorstyle); if (overstyleId != ObjectId.Null) { dps = trans.GetObject(overstyleId, OpenMode.ForRead) as DisplayProperties; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Style override Style Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n"); continue; } ObjectId defaultDpsId = dr.DefaultDisplayPropertiesId; if (!defaultDpsId.IsNull) { dps = trans.GetObject(defaultDpsId, OpenMode.ForRead) as DisplayProperties; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Default Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n"); } } trans.Commit(); } catch (System.Exception) { trans.Abort(); } finally { trans.Dispose(); } return; }
/// <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; } }