private static void makeAnnoOverrides( Document doc, View view, List <List <string> > category_colors) { try { StringBuilder sb = new StringBuilder(); var col = new FilteredElementCollector(doc, view.Id) .WhereElementIsNotElementType(); var colorcats = category_colors.Select(x => x.First()).ToList(); using (Transaction tx = new Transaction(doc)) { var tohide = new List <ElementId>(); tx.Start("SetViewtxz"); foreach (Element elem in col) { try { if (elem.Category != null) { var elemBcCat = (BuiltInCategory)elem.Category.Id.IntegerValue; string bcCat = elemBcCat.ToString(); if (!colorcats.Contains(bcCat)) { tohide.Add(elem.Id); } } } catch (Exception) { } } SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, Helper.RandomString(100)); filterElement.SetElementIds(tohide); doc.Regenerate(); view.AddFilter(filterElement.Id); view.SetFilterVisibility(filterElement.Id, false); tx.Commit(); } } catch (Exception) { } }
public static void cropExtentAnno(Document doc, View view) { try { var els = new FilteredElementCollector(doc, view.Id) .WhereElementIsNotElementType(); var bbv = view.get_BoundingBox(view); var maxx = bbv.Max.X; var maxy = bbv.Max.Y; var maxz = bbv.Max.Z; var minx = bbv.Min.X; var miny = bbv.Min.Y; var minz = bbv.Min.Z; var tohide = new List <ElementId>(); foreach (Element e in els) { try { var elemBcCat = (BuiltInCategory)e.Category.Id.IntegerValue; string bcCat = elemBcCat.ToString(); if (bcCat.Contains("Tag") || bcCat.Contains("Arrow") || bcCat.Contains("Callo") || bcCat.Contains("OST_Grid") || bcCat.Contains("Elevation") || bcCat.Contains("Annotation") || bcCat.Contains("View") //|| bcCat.Contains("Line") || bcCat.Contains("Level") || bcCat.Contains("Section") || bcCat.Contains("Dimension") //|| bcCat.Contains("Text") ) { var bbx = e.get_BoundingBox(view); if (maxx < bbx.Max.X || maxy < bbx.Max.Y || maxz < bbx.Max.Z || minx > bbx.Min.X || miny > bbx.Min.Y || minz > bbx.Min.Z) { tohide.Add(e.Id); } } //if (bcCat.Contains("OST_Grid")) //{ // var bbx = e.get_BoundingBox(view); // //Intersect // if(bbx.) //} } catch (Exception) { } } using (Transaction tx = new Transaction(doc)) { tx.Start("shade"); SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, RandomString(100)); filterElement.SetElementIds(tohide); doc.Regenerate(); view.AddFilter(filterElement.Id); view.SetFilterVisibility(filterElement.Id, false); tx.Commit(); } } catch (Exception) { } }
private static void AddOverride2(Document doc, View view, ElementId pattern, List <List <string> > category_colors) { try { FilteredElementCollector col = new FilteredElementCollector(doc, view.Id) .WhereElementIsNotElementType(); StringBuilder sb = new StringBuilder(); using (Transaction tx = new Transaction(doc)) { var tohide = new List <ElementId>(); tx.Start("SetViewtx"); try { foreach (Element elem in col) { try { // var catid = elem.Category.Id.IntegerValue; var elemBcCat = (BuiltInCategory)elem.Category.Id.IntegerValue; string bcCat = elemBcCat.ToString(); var category_ovrs = category_colors.Where(x => x.First() == elemBcCat.ToString()).ToList(); if (category_ovrs.Count > 0) { var category_ovr = category_ovrs.First(); var r = Convert.ToByte(category_ovr[1]); var g = Convert.ToByte(category_ovr[2]); var b = Convert.ToByte(category_ovr[3]); var color_c = new Color(r, g, b); var gSettings = new OverrideGraphicSettings(); //gSettings. gSettings.SetCutFillColor(color_c); gSettings.SetCutLineColor(color_c); gSettings.SetCutFillPatternVisible(true); gSettings.SetCutFillPatternId(pattern); gSettings.SetProjectionFillColor(color_c); gSettings.SetProjectionLineColor(color_c); gSettings.SetProjectionFillPatternId(pattern); view.SetElementOverrides(elem.Id, gSettings); } else { //!elem.Category.HasMaterialQuantities || if (elemBcCat.ToString().Contains("Tag") || elemBcCat.ToString().Contains("Arrow") || elemBcCat.ToString().Contains("Text") || elemBcCat.ToString().Contains("Annotation") || elemBcCat.ToString().Contains("Line")) { tohide.Add(elem.Id); } } } catch (Exception e) { sb.AppendLine(); sb.Append("Fail--OVERRIDES:" + view.ViewName + e.ToString()); //File.AppendAllText(FileManager.logfile, sb.ToString() + "\n"); } } } catch (Exception) { // TaskDialog.Show("x", e.ToString()); } SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, "tags filter"); filterElement.SetElementIds(tohide); // doc.Regenerate(); view.AddFilter(filterElement.Id); view.SetFilterVisibility(filterElement.Id, false); // view. tx.Commit(); } } catch (Exception) { } }