I'm looking for vb.net code to get a layer's viewport overrides. What i'm looking to do is to click on a layer and have a dialog box open with the override into i.e. color name, linetype name....
I just saw your post looking for something - not sure if you have found a solution, but here is something that may help (in c# though). there are a few sites that can translate for you
static public void ApplyColourOverride() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Collection of our selected entities and their sub-ent paths ObjectIdCollection ids; List<FullSubentityPath> paths; // Flag for whether a REGEN will be required bool regenRequired = false; // Start a transaction... will initially be used // to highlight the selected entities and then to // modify their color Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { if (SelectNestedEntities(ed, out ids, out paths) && ids.Count > 0) { // Get the new color index Autodesk.AutoCAD.Windows.ColorDialog cd = new ColorDialog(); System.Windows.Forms.DialogResult res = cd.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { for (int i = 0; i < ids.Count; i++) { Entity ent = tr.GetObject(ids[i], OpenMode.ForWrite) as Entity; if (ent != null) { regenRequired = true; //get the layer name string layerName = ent.Layer; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[layerName], OpenMode.ForWrite); LayerViewportProperties lvpo = ltr.GetViewportOverrides(ed.CurrentViewportObjectId); lvpo.Color = cd.Color; //ent.ColorIndex = pir.Value; } } } else if (res == System.Windows.Forms.DialogResult.Cancel) { } } UnhighlightSubEntities(paths); tr.Commit(); } // Regen reflects the new color if (regenRequired) ed.Regen(); } static public void ApplyLinetypeOverride() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Collection of our selected entities and their sub-ent paths ObjectIdCollection ids; List<FullSubentityPath> paths; // Flag for whether a REGEN will be required bool regenRequired = false; // Start a transaction... will initially be used // to highlight the selected entities and then to // modify their color Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { if (SelectNestedEntities(ed, out ids, out paths) && ids.Count > 0) { // Get the new color index Autodesk.AutoCAD.Windows.LinetypeDialog cd = new LinetypeDialog(); System.Windows.Forms.DialogResult res = cd.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { for (int i = 0; i < ids.Count; i++) { Entity ent = tr.GetObject(ids[i], OpenMode.ForWrite) as Entity; if (ent != null) { regenRequired = true; //get the layer name string layerName = ent.Layer; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[layerName], OpenMode.ForWrite); LayerViewportProperties lvpo = ltr.GetViewportOverrides(ed.CurrentViewportObjectId); lvpo.LinetypeObjectId = cd.Linetype; //ent.ColorIndex = pir.Value; } } } else if (res == System.Windows.Forms.DialogResult.Cancel) { } } UnhighlightSubEntities(paths); tr.Commit(); } // Regen reflects the new color if (regenRequired) ed.Regen(); } static public void ApplyLineweightOverride() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Collection of our selected entities and their sub-ent paths ObjectIdCollection ids; List<FullSubentityPath> paths; // Flag for whether a REGEN will be required bool regenRequired = false; // Start a transaction... will initially be used // to highlight the selected entities and then to // modify their color Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { if (SelectNestedEntities(ed, out ids, out paths) && ids.Count > 0) { // Get the new color index Autodesk.AutoCAD.Windows.LineWeightDialog cd = new LineWeightDialog(); System.Windows.Forms.DialogResult res = cd.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { for (int i = 0; i < ids.Count; i++) { Entity ent = tr.GetObject(ids[i], OpenMode.ForWrite) as Entity; if (ent != null) { regenRequired = true; //get the layer name string layerName = ent.Layer; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[layerName], OpenMode.ForWrite); LayerViewportProperties lvpo = ltr.GetViewportOverrides(ed.CurrentViewportObjectId); lvpo.LineWeight = cd.LineWeight; //ent.ColorIndex = pir.Value; } } } else if (res == System.Windows.Forms.DialogResult.Cancel) { } } UnhighlightSubEntities(paths); tr.Commit(); } // Regen reflects the new color if (regenRequired) ed.Regen(); } private static bool SelectNestedEntities(Editor ed, out ObjectIdCollection ids, out List<FullSubentityPath> paths) { ids = new ObjectIdCollection(); paths = new List<FullSubentityPath>(); // Loop until cancelled or completed PromptNestedEntityResult rs; PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("\nSelect nested entity: "); pneo.AllowNone = true; do { rs = ed.GetNestedEntity(pneo); if (rs.Status == PromptStatus.OK) { ids.Add(rs.ObjectId); FullSubentityPath path = HighlightSubEntity(rs); if (path != FullSubentityPath.Null) paths.Add(path); } } while (rs.Status == PromptStatus.OK); // Return whether the function was cancelled return (rs.Status != PromptStatus.Cancel); } private static void UnhighlightSubEntities(List<FullSubentityPath> paths) { for (int i = 0; i < paths.Count; i++) { ObjectId[] ids = paths[i].GetObjectIds(); Entity ent = ids[0].GetObject(OpenMode.ForRead) as Entity; if (ent != null) { ent.Unhighlight(paths[i], false); } } } private static FullSubentityPath HighlightSubEntity(PromptNestedEntityResult rs) { // Extract relevant information from the prompt object ObjectId selId = rs.ObjectId; List<ObjectId> objIds = new List<ObjectId>(rs.GetContainers()); // Reverse the "containers" list objIds.Reverse(); // Now append the selected entity objIds.Add(selId); // Retrieve the sub-entity path for this entity SubentityId subEnt = new SubentityId(SubentityType.Null, System.IntPtr.Zero); FullSubentityPath path = new FullSubentityPath(objIds.ToArray(), subEnt); // Open the outermost container, relying on the open // transaction... Entity ent = objIds[0].GetObject(OpenMode.ForRead) as Entity; // ... and highlight the nested entity if (ent == null) return FullSubentityPath.Null; ent.Highlight(path, false); // Return the sub-entity path for later unhighlighting return path; }
I hope this helps.
Hi, I have the same question, anyone can help.
Brent Burgess, thanks a lot for above code, but that is for set not get. I want to find out the override detail, saying which layer is overrided, color or linetype overrided, and then take different actions.
Thanks in advance
@Anonymous
Take a look at GetViewportOverrides
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[layerName], OpenMode.ForWrite); LayerViewportProperties lvpo = ltr.GetViewportOverrides(ed.CurrentViewportObjectId);
Can't find what you're looking for? Ask the community or share your knowledge.