private void UnHiLighted(ElementId elementId, UIDocument uiDoc, Document doc) { OverrideGraphicSettings ogs = new OverrideGraphicSettings(); // Color red = new Color(255, 0, 0); Element solidFill = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Where(q => q.Name.Contains("單色填滿")).First(); // ogs.SetProjectionLineColor(red); // ogs.SetProjectionLineWeight(8); ogs.SetProjectionFillPatternId(ElementId.InvalidElementId); ogs.SetProjectionFillColor(Color.InvalidColorValue); ogs.SetCutFillPatternId(ElementId.InvalidElementId); ogs.SetCutFillColor(Color.InvalidColorValue); using (Transaction t = new Transaction(doc, "Highlight element")) { t.Start(); try { // elementId = Id of element you wish to highlight uiDoc.ActiveView.SetElementOverrides(elementId, ogs); } catch (Exception ex) { TaskDialog.Show("Exception", ex.ToString()); } uiDoc.RefreshActiveView(); t.Commit(); } }
public static void ApplyViewFilter(Document doc, View view, ParameterFilterElement filter, ElementId solidFillPatternId, int colorNumber, bool colorLines, bool colorFill) { view.AddFilter(filter.Id); OverrideGraphicSettings ogs = new OverrideGraphicSettings(); byte red = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(1, 2), 16); byte green = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(3, 2), 16); byte blue = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(5, 2), 16); Color clr = new Color(red, green, blue); if (colorLines) { ogs.SetProjectionLineColor(clr); ogs.SetCutLineColor(clr); } if (colorFill) { #if R2017 || R2018 ogs.SetProjectionFillColor(clr); ogs.SetProjectionFillPatternId(solidFillPatternId); ogs.SetCutFillColor(clr); ogs.SetCutFillPatternId(solidFillPatternId); #else ogs.SetSurfaceForegroundPatternColor(clr); ogs.SetSurfaceForegroundPatternId(solidFillPatternId); ogs.SetCutForegroundPatternColor(clr); ogs.SetCutForegroundPatternId(solidFillPatternId); #endif } view.SetFilterOverrides(filter.Id, ogs); }
public static void AddFilterToView( Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement, Color cutFillColor, string[] cutFillPatterns, Color projFillColor, string[] projFillPatterns) { using (Transaction t = new Transaction(doc, "Add filter to view and set overrides")) { t.Start(); ElementId filterId = filterElement.Id; view.AddFilter(filterId); doc.Regenerate(); OverrideGraphicSettings overrideSettings = view.GetFilterOverrides(filterId); Element cutFill = (from element in new FilteredElementCollector(doc) .OfClass(typeof(FillPatternElement)).Cast <Element>() where cutFillPatterns.Any(pattern => pattern.Equals(element.Name)) select element) .FirstOrDefault(); Element projectFill = (from element in new FilteredElementCollector(doc) .OfClass(typeof(FillPatternElement)).Cast <Element>() where projFillPatterns.Any(pattern => pattern.Equals(element.Name)) select element) .FirstOrDefault(); overrideSettings.SetCutFillColor(cutFillColor); overrideSettings.SetCutFillPatternId(cutFill.Id); overrideSettings.SetProjectionFillColor(projFillColor); overrideSettings.SetProjectionFillPatternId(projectFill.Id); view.SetFilterOverrides(filterId, overrideSettings); t.Commit(); } }
public static OverrideGraphicSettings GetOverrideGraphicSettings(Color color, ElementId fillPatternId, int transparency) { OverrideGraphicSettings settings = new OverrideGraphicSettings(); settings.SetCutFillColor(color); settings.SetCutFillPatternId(fillPatternId); settings.SetCutLineColor(color); settings.SetCutLinePatternId(fillPatternId); settings.SetProjectionFillColor(color); settings.SetProjectionFillPatternId(fillPatternId); settings.SetProjectionLineColor(color); settings.SetProjectionLinePatternId(fillPatternId); settings.SetSurfaceTransparency(transparency); return(settings); }
public OverrideCat(Document doc, ElementId pattern, List <string> category_ovr) { BuiltInCategory category = Helper.GetCategories(category_ovr[0]); 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); foreach (Category elem in doc.Settings.Categories) { try { if (elem != null) { var elemBcCat = (BuiltInCategory)elem.Id.IntegerValue; string bcCat = elemBcCat.ToString(); if (category_ovr[0] == bcCat) { this.categ = elem; } } } catch (Exception) { } } var gSettings = new OverrideGraphicSettings(); gSettings.SetSurfaceTransparency(0); 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); this.builtincategory = category; this.overrides = gSettings; this.visible = true; }
public static Element Create(this Grevit.Types.Filter filter) { List<ElementId> categories = new List<ElementId>(); Dictionary<string,ElementId> parameters = new Dictionary<string,ElementId>(); foreach (Category category in GrevitBuildModel.document.Settings.Categories) { if (filter.categories.Contains(category.Name) || filter.categories.Count == 0) categories.Add(category.Id); FilteredElementCollector collector = new FilteredElementCollector(GrevitBuildModel.document).OfCategoryId(category.Id); if (collector.Count() > 0) { foreach (Autodesk.Revit.DB.Parameter parameter in collector.FirstElement().Parameters) if (!parameters.ContainsKey(parameter.Definition.Name)) parameters.Add(parameter.Definition.Name, parameter.Id); } } ParameterFilterElement parameterFilter = null; FilteredElementCollector collect = new FilteredElementCollector(GrevitBuildModel.document).OfClass(typeof(ParameterFilterElement)); foreach (ParameterFilterElement existingFilter in collect.ToElements()) { if (existingFilter.Name == filter.name) { existingFilter.ClearRules(); parameterFilter = existingFilter; } } if (parameterFilter == null) parameterFilter = ParameterFilterElement.Create(GrevitBuildModel.document, filter.name, categories); View view = (View)Utilities.GetElementByName(GrevitBuildModel.document, typeof(View), filter.view); view.AddFilter(parameterFilter.Id); #region Apply Rules List<FilterRule> filterRules = new List<FilterRule>(); foreach (Grevit.Types.Rule rule in filter.Rules) { if (parameters.ContainsKey(rule.name)) { FilterRule filterRule = rule.ToRevitRule(parameters[rule.name]); if (filterRule != null) filterRules.Add(filterRule); } } parameterFilter.SetRules(filterRules); #endregion #region Apply Overrides OverrideGraphicSettings filterSettings = new OverrideGraphicSettings(); // Apply Colors if (filter.CutFillColor != null) filterSettings.SetCutFillColor(filter.CutFillColor.ToRevitColor()); if (filter.ProjectionFillColor != null) filterSettings.SetProjectionFillColor(filter.ProjectionFillColor.ToRevitColor()); if (filter.CutLineColor != null) filterSettings.SetCutLineColor(filter.CutLineColor.ToRevitColor()); if (filter.ProjectionLineColor != null) filterSettings.SetProjectionLineColor(filter.ProjectionLineColor.ToRevitColor()); // Apply Lineweight if (filter.CutLineWeight != -1) filterSettings.SetCutLineWeight(filter.CutLineWeight); if (filter.ProjectionLineWeight != -1) filterSettings.SetProjectionLineWeight(filter.ProjectionLineWeight); // Apply Patterns if (filter.CutFillPattern != null) { FillPatternElement pattern = (FillPatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(FillPatternElement), filter.CutFillPattern); filterSettings.SetCutFillPatternId(pattern.Id); } if (filter.ProjectionFillPattern != null) { FillPatternElement pattern = (FillPatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(FillPatternElement), filter.ProjectionFillPattern); filterSettings.SetProjectionFillPatternId(pattern.Id); } if (filter.CutLinePattern != null) { LinePatternElement pattern = (LinePatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(LinePatternElement), filter.CutLinePattern); filterSettings.SetCutLinePatternId(pattern.Id); } if (filter.ProjectionLinePattern != null) { LinePatternElement pattern = (LinePatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(LinePatternElement), filter.ProjectionLinePattern); filterSettings.SetProjectionLinePatternId(pattern.Id); } view.SetFilterOverrides(parameterFilter.Id, filterSettings); #endregion return parameterFilter; }
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) { } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Debug.Listeners.Clear(); Debug.Listeners.Add(new RbsLogger.Logger("WallHatch")); Document doc = commandData.Application.ActiveUIDocument.Document; View curView = doc.ActiveView; if (!(curView is ViewPlan)) { message = "Запуск команды возможен только на плане"; Debug.WriteLine(message); return(Result.Failed); } if (curView.ViewTemplateId != null && curView.ViewTemplateId != ElementId.InvalidElementId) { message = "Для вида применен шаблон. Отключите шаблон вида перед запуском"; Debug.WriteLine(message); return(Result.Failed); } Selection sel = commandData.Application.ActiveUIDocument.Selection; Debug.WriteLine("Selected elements: " + sel.GetElementIds().Count); if (sel.GetElementIds().Count == 0) { message = "Не выбраны стены."; return(Result.Failed); } List <Wall> walls = new List <Wall>(); foreach (ElementId id in sel.GetElementIds()) { Wall w = doc.GetElement(id) as Wall; if (w == null) { continue; } walls.Add(w); } Debug.WriteLine("Walls count: " + walls.Count); if (walls.Count == 0) { message = "Не выбраны стены."; return(Result.Failed); } SortedDictionary <double, List <Wall> > wallHeigthDict = new SortedDictionary <double, List <Wall> >(); if (wallHeigthDict.Count > 10) { message = "Слишком много типов стен! Должно быть не более 10"; Debug.WriteLine(message); return(Result.Failed); } foreach (Wall w in walls) { Debug.WriteLine("Current wall id:" + w.Id.IntegerValue); double topElev = GetWallTopElev(doc, w, true); Debug.WriteLine("Top elevation: " + topElev.ToString("F1")); if (wallHeigthDict.ContainsKey(topElev)) { wallHeigthDict[topElev].Add(w); } else { wallHeigthDict.Add(topElev, new List <Wall> { w }); } } List <ElementId> catsIds = new List <ElementId> { new ElementId(BuiltInCategory.OST_Walls) }; int i = 1; using (Transaction t = new Transaction(doc)) { t.Start("Отметки стен"); foreach (ElementId filterId in curView.GetFilters()) { ParameterFilterElement filter = doc.GetElement(filterId) as ParameterFilterElement; if (filter.Name.StartsWith("_cwh_")) { curView.RemoveFilter(filterId); } } Debug.WriteLine("Old filters deleted"); foreach (var kvp in wallHeigthDict) { Debug.WriteLine("Current key: " + kvp.Key.ToString("F1")); ElementId hatchId = GetHatchIdByNumber(doc, i); ImageType image = GetImageTypeByNumber(doc, i); double curHeigthMm = kvp.Key; double curHeigthFt = curHeigthMm / 304.8; List <Wall> curWalls = kvp.Value; foreach (Wall w in curWalls) { w.get_Parameter(BuiltInParameter.ALL_MODEL_IMAGE).Set(image.Id); w.LookupParameter("Рзм.ОтметкаВерха").Set(curHeigthFt); double bottomElev = GetWallTopElev(doc, w, false); double bottomElevFt = bottomElev / 304.8; w.LookupParameter("Рзм.ОтметкаНиза").Set(bottomElevFt); } string filterName = "_cwh_" + "Стены Рзм.ОтметкаВерха равно " + curHeigthMm.ToString("F0"); MyParameter mp = new MyParameter(curWalls.First().LookupParameter("Рзм.ОтметкаВерха")); ParameterFilterElement filter = FilterCreator.createSimpleFilter(doc, catsIds, filterName, mp, CriteriaType.Equals); curView.AddFilter(filter.Id); OverrideGraphicSettings ogs = new OverrideGraphicSettings(); #if R2017 || R2018 ogs.SetProjectionFillPatternId(hatchId); ogs.SetCutFillPatternId(hatchId); #else ogs.SetSurfaceForegroundPatternId(hatchId); ogs.SetCutForegroundPatternId(hatchId); #endif curView.SetFilterOverrides(filter.Id, ogs); i++; } t.Commit(); } return(Result.Succeeded); }