Last active
December 25, 2015 13:29
-
-
Save benhumphrey/6983987 to your computer and use it in GitHub Desktop.
Revit API visibility conroller for element subcategories. In particular, for imported dwg files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Autodesk.Revit.DB; | |
namespace dwgVisControl | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] | |
[Autodesk.Revit.VSTA.AddInId("cd81988f-f334-4f9b-b8a3-b6bc4993d9d6")] | |
public partial class ThisDocument | |
{ | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
#region VSTA generated code | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(Module_Startup); | |
this.Shutdown += new System.EventHandler(Module_Shutdown); | |
} | |
#endregion | |
/// <summary> | |
/// Receives 2 string arrays. | |
/// One with characters to match anywhere in layer name | |
/// One with characters to match at end of layer name. Layers matching any | |
/// of the string comparisons have their visibility turned off. | |
/// </summary> | |
/// <param name="strContains">String Array for the Contains comparison</param> | |
/// <param name="strEndsWith">String Array for the EndsWith comparison</param> | |
private void Hider(String[] strContains, String[] strEndsWith) | |
{ | |
///Grab the active view from the active document | |
Document doc = this.Document; | |
View view = Document.ActiveView; | |
///Start a Revit transaction on the active document | |
using (Transaction t = new Transaction(doc, "Change Imported dwg visibility")) | |
{ | |
t.Start(); | |
///1. Iterate through all categories in the active document to find imported dwgs | |
///2. Grab subcategories (same as layers) from each dwg | |
///3. Step through each subcategory (each layer in dwg) | |
///4. Perform string comparisons on layer names and adjust visibility if matched | |
foreach (Category cat in view.Document.Settings.Categories) | |
if (cat.Name.EndsWith(".dwg")) | |
{ | |
CategoryNameMap objA = cat.SubCategories; | |
CategoryNameMapIterator objB = objA.ForwardIterator(); | |
while (objB.MoveNext()) | |
{ | |
Category cat2 = objA.get_Item(objB.Key); | |
foreach (string s in strContains) | |
{ | |
if (cat2.Name.Contains(s)) | |
{ | |
cat2.set_Visible(doc.ActiveView, false); | |
} | |
} | |
foreach (string s in strEndsWith) | |
{ | |
if (cat2.Name.Contains(s)) | |
{ | |
cat2.set_Visible(doc.ActiveView, false); | |
} | |
} | |
} | |
} | |
t.Commit(); | |
} | |
} | |
public void Hide20Scale() | |
{ | |
String[] strCon = new string[] { }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { "-20" }; ///Define a list of characters to match in each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void Hide40Scale() | |
{ | |
String[] strCon = new string[] { }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { "-40" }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void HideBase() | |
{ | |
String[] strCon = new string[] { "BASE" }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void HideChannelization() | |
{ | |
String[] strCon = new string[] { "TCHN" }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void HideOver() | |
{ | |
String[] strCon = new string[] { "OVER" , "OVR" }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void HideUnder() | |
{ | |
String[] strCon = new string[] { "UND"}; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
public void HideAnnotations() | |
{ | |
String[] strCon = new string[] { "-A-" , "TXT" , "TTXT" , "-A_" }; ///Define a list of characters to match in each dwg layer name | |
String[] strEnd = new string[] { "-A" }; ///Define a list of characters to match at the end of each dwg layer name | |
Hider(strCon, strEnd); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment