Beispiel #1
0
        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);
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
        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();
            }
        }
        void SetOneFloorColor(Document doc, FillPatternElement fillPatternElement, ElementId floorId, Autodesk.Revit.DB.Color color)
        {
            OverrideGraphicSettings OverrideGraphicSettings = new OverrideGraphicSettings();

            OverrideGraphicSettings = doc.ActiveView.GetElementOverrides(floorId);
            OverrideGraphicSettings.SetProjectionFillPatternId(fillPatternElement.Id);

            OverrideGraphicSettings.SetProjectionFillColor(color);
            doc.ActiveView.SetElementOverrides(floorId, OverrideGraphicSettings);
        }
Beispiel #5
0
        /// <summary>
        /// 为面层实体设置颜色、类型等参数
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="ds"></param>
        /// <param name="volumn"></param>
        /// <param name="area"></param>
        /// <param name="faceOptions"></param>
        private void SetParameters(Transaction tran, DirectShape ds, double volumn, double area, FaceOptions faceOptions)
        {
            // 设置实体对象在指定视力中的填充颜色
            OverrideGraphicSettings gs = _view.GetElementOverrides(ds.Id);

            // 填充颜色
            gs.SetProjectionFillColor(faceOptions.Color);

            // 填充模式

            string             fillPatternName = "实体填充";
            FillPatternElement fpe             = FillPatternElement.GetFillPatternElementByName(_doc, FillPatternTarget.Drafting, fillPatternName);

            if (fpe == null)
            {
                fpe = FillPatternElement.Create(_doc,
                                                new FillPattern(fillPatternName, FillPatternTarget.Drafting, FillPatternHostOrientation.ToHost));
            }

            gs.SetProjectionFillPatternId(fpe.Id);
            gs.SetProjectionFillPatternVisible(true);
            _view.SetElementOverrides(ds.Id, gs);

            // 设置参数
            Parameter p;

            // 面层对象标识
            p = ds.get_Parameter(FaceWallParameters.sp_FaceIdTag_guid);
            if (p != null)
            {
                p.Set(FaceWallParameters.FaceIdentificaion);
            }

            // 面积
            p = ds.get_Parameter(FaceWallParameters.sp_Area_guid);
            if (p != null)
            {
                p.Set(area);
            }

            // 体积
            p = ds.get_Parameter(FaceWallParameters.sp_Volumn_guid);
            if (p != null)
            {
                p.Set(volumn);
            }

            // 类型
            p = ds.get_Parameter(FaceWallParameters.sp_FaceType_guid);
            if (p != null)
            {
                p.Set(faceOptions.FaceType);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Save an element on a temporary list and override its color
        /// </summary>
        public static void AddToSelection(Element ReferenceElem, List <string> ListElemntsStrings, List <Element> completeList, bool checkBox)
        {
            Category        category      = ReferenceElem.Category;
            BuiltInCategory enumCategory  = (BuiltInCategory)category.Id.IntegerValue;
            BuiltInCategory builtCategory = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), ReferenceElem.Category.Id.ToString());

            if (checkBox == true)
            {
                foreach (Element elem in completeList)
                {
                    Category        cat     = elem.Category;
                    BuiltInCategory enumCat = (BuiltInCategory)cat.Id.IntegerValue;

                    if (enumCat.ToString() == "OST_FabricationDuctwork" &&
                        getNumber(elem) == "" && elem.get_Parameter(BuiltInParameter.FABRICATION_PART_DEPTH_IN) != null)
                    {
                        if (filterParam(ReferenceElem, elem, BuiltInParameter.ELEM_FAMILY_PARAM,
                                        BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN,
                                        BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM,
                                        BuiltInParameter.FABRICATION_PART_LENGTH))
                        {
                            selectedElements.Add(elem);
                        }
                    }
                }
                if (!selectedElements.Contains(ReferenceElem) && tools.getNumber(ReferenceElem) == "")
                {
                    selectedElements.Add(ReferenceElem);
                }
            }
            else
            {
                if (getNumber(ReferenceElem) == "")
                {
                    selectedElements.Add(ReferenceElem);
                }
            }


            OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();

            System.Drawing.Color colorSelect = MainForm.ColorSelected;
            byte r = colorSelect.R;
            byte b = colorSelect.B;
            byte g = colorSelect.G;

            overrideGraphicSettings.SetProjectionFillColor(new Autodesk.Revit.DB.Color(r, g, b));
            overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(r, g, b));
            foreach (Element x in tools.selectedElements)
            {
                tools.doc.ActiveView.SetElementOverrides(x.Id, overrideGraphicSettings);
            }
        }
Beispiel #7
0
        public static void Graphics20172020(Document doc, ref OverrideGraphicSettings overrideGraphicSettings, byte r, byte g, byte b)
        {
#if REVIT2019
            var patternCollector = new FilteredElementCollector(doc);
            patternCollector.OfClass(typeof(FillPatternElement));
            FillPatternElement fpe = patternCollector.ToElements()
                                     .Cast <FillPatternElement>().First(x => x.GetFillPattern().Name.Contains("Solid fill"));
            overrideGraphicSettings.SetProjectionFillPatternId(fpe.Id);
            overrideGraphicSettings.SetProjectionFillPatternVisible(true);
            overrideGraphicSettings.SetProjectionFillColor(new Autodesk.Revit.DB.Color(r, g, b));
            overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(r, g, b));
#endif
        }
Beispiel #8
0
 public static void SetColor(this Element elem, View view, byte r, byte g, byte b)
 {
     try
     {
         Color val = new Color(r, g, b);
         OverrideGraphicSettings val2 = new OverrideGraphicSettings();
         val2.SetProjectionLineColor(val);
         val2.SetProjectionFillColor(val);
         view.SetElementOverrides(elem.Id, val2);
     }
     catch
     {
     }
 }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        public static OverrideGraphicSettings getStandartGraphicSettings(Document doc)
        {
            OverrideGraphicSettings overrideGraphic = new OverrideGraphicSettings();

#if Revit2018
            overrideGraphic.SetProjectionFillPatternId(ElementId.InvalidElementId);
            overrideGraphic.SetProjectionFillColor(Color.InvalidColorValue);
#endif
#if Revit2020
            overrideGraphic.SetSurfaceForegroundPatternId(ElementId.InvalidElementId);
            overrideGraphic.SetSurfaceForegroundPatternColor(Color.InvalidColorValue);
#endif
            overrideGraphic.SetProjectionLineColor(Color.InvalidColorValue);

            return(overrideGraphic);
        }
        /// <summary>
        /// Override colors in view by prefix
        /// </summary>
        public static void ColorInView()
        {
            using (Transaction ResetView = new Transaction(tools.uidoc.Document, "Reset view"))
            {
                ResetView.Start();
                OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();

                LogicalOrFilter logicalOrFilter = new LogicalOrFilter(filters());

                var collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(
                    logicalOrFilter).WhereElementIsNotElementType();

                Dictionary <Element, string> elemtNPrefix = new Dictionary <Element, string>();
                Dictionary <string, Color>   colorNPrefix = new Dictionary <string, Color>();

                //Create a Dictionary with Elements and its prefixes
                foreach (var item in collector.ToElements())
                {
                    var number     = getNumber(item);
                    var itemNumber = GetNumberAndPrexif(number);
                    if (itemNumber != null)
                    {
                        elemtNPrefix.Add(item, itemNumber.Item1);
                    }
                }

                //Create a unique prefixes and an assigned color
                foreach (var prefix in elemtNPrefix.Values.Distinct())
                {
                    //Chanchada
                    System.Threading.Thread.Sleep(50);
                    Random randonGen   = new Random();
                    Color  randomColor = Color.FromArgb(1, randonGen.Next(255), randonGen.Next(255), randonGen.Next(255));
                    colorNPrefix.Add(prefix, randomColor);
                }

                //Override colors following the already created schema of colors
                foreach (var item in elemtNPrefix)
                {
                    overrideGraphicSettings.SetProjectionFillColor(new Autodesk.Revit.DB.Color(colorNPrefix[item.Value].R, colorNPrefix[item.Value].G, colorNPrefix[item.Value].B));
                    overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(colorNPrefix[item.Value].R, colorNPrefix[item.Value].G, colorNPrefix[item.Value].B));
                    doc.ActiveView.SetElementOverrides(item.Key.Id, overrideGraphicSettings);
                }

                ResetView.Commit();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Override the element's color in the active view.
        /// </summary>
        /// <param name="color">The color to apply to a solid fill on the element.</param>
        public void OverrideColorInView(Color color)
        {
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            var view = DocumentManager.Instance.CurrentUIDocument.ActiveView;
            var ogs  = new OverrideGraphicSettings();

            var patternCollector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);

            patternCollector.OfClass(typeof(FillPatternElement));
            FillPatternElement solidFill = patternCollector.ToElements().Cast <FillPatternElement>().First(x => x.GetFillPattern().Name == "Solid fill");

            ogs.SetProjectionFillColor(new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue));
            ogs.SetProjectionFillPatternId(solidFill.Id);
            view.SetElementOverrides(this.InternalElementId, ogs);

            TransactionManager.Instance.TransactionTaskDone();
        }
        OverrideGraphicSettings GetOverrideGraphicSettings(Document doc)
        {
            var setting = new OverrideGraphicSettings();

            setting.SetHalftone(IsHalftone);
            setting.SetProjectionFillPatternVisible(IsSurfaceVisible);
            setting.SetProjectionFillColor(new Color(Color.R, Color.G, Color.B));
            if (FillerId == -1)
            {
                setting.SetProjectionFillPatternId(GetDefaultFillPatternId(doc));
            }
            else
            {
                setting.SetProjectionFillPatternId(new ElementId(FillerId));
            }
            setting.SetSurfaceTransparency(SurfaceTransparency);
            return(setting);
        }
        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;
        }
Beispiel #15
0
        void ChangeColor(Document doc, ElementId id)
        {
            byte  _R    = (byte)new Random().Next(0, 255);
            byte  _G    = (byte)new Random().Next(0, 255);
            byte  _B    = (byte)new Random().Next(0, 255);
            Color color = new Color(255, _G, _B);
            //Color color = new Color(255,0,0);
            FillPatternElement      fp  = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).First(m => (m as FillPatternElement).GetFillPattern().IsSolidFill) as FillPatternElement;
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

            ogs.SetProjectionFillPatternId(fp.Id);
            ogs.SetProjectionFillColor(color);

            using (Transaction ts = new Transaction(doc, "change element color"))
            {
                ts.Start();
                doc.ActiveView.SetElementOverrides(id, ogs);
                ts.Commit();
            }
        }
Beispiel #16
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var color = (System.Drawing.Color)((Value.Container)args[0]).Item;
            var elem  = (Element)((Value.Container)args[1]).Item;

            var view = dynRevitSettings.Doc.ActiveView;
            var ogs  = new OverrideGraphicSettings();

            if (solidFill == null)
            {
                var patternCollector = new FilteredElementCollector(dynRevitSettings.Doc.Document);
                patternCollector.OfClass(typeof(FillPatternElement));
                solidFill = patternCollector.ToElements().Cast <FillPatternElement>().First(x => x.GetFillPattern().Name == "Solid fill");
            }

            ogs.SetProjectionFillColor(new Autodesk.Revit.DB.Color(color.R, color.G, color.B));
            ogs.SetProjectionFillPatternId(solidFill.Id);
            view.SetElementOverrides(elem.Id, ogs);

            return(Value.NewNumber(1));
        }
Beispiel #17
0
        private OverrideGraphicSettings getGraphicSettings(Color color)
        {
            FillPatternElement fillPattern = null;

            List <Element> fillPatterns = new FilteredElementCollector(doc)
                                          .OfClass(typeof(FillPatternElement))
                                          .WhereElementIsNotElementType()
                                          .ToElements()
                                          .ToList();

            foreach (var fp in fillPatterns)
            {
                if (fp.Name.ToString().Contains("Сплошная заливка"))
                {
                    fillPattern = (FillPatternElement)fp;
                    break;
                }
            }
            if (fillPattern == null)
            {
                Print("Заливка \"Сплошная заливка\" не найдена", KPLN_Loader.Preferences.MessageType.Error);
                return(null);
            }

            OverrideGraphicSettings overrideGraphic = new OverrideGraphicSettings();

#if Revit2018
            overrideGraphic.SetProjectionFillPatternId(fillPattern.Id);
            overrideGraphic.SetProjectionFillColor(color);
#endif
#if Revit2020
            overrideGraphic.SetSurfaceForegroundPatternId(fillPattern.Id);
            overrideGraphic.SetSurfaceForegroundPatternColor(color);
#endif
            overrideGraphic.SetProjectionLineColor(color);

            return(overrideGraphic);
        }
        /// <summary>
        /// Save an element on a temporary list and override its color
        /// </summary>
        public static void AddToSelection()
        {
            selectedElements.Clear();

            var filterS = new SelectionFilter();

            var refElement = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new SelectionFilter());

            if (refElement != null)
            {
                var element = uidoc.Document.GetElement(refElement);

                Category        category     = element.Category;
                BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;


                //Check for other rectangular ducts with the same parameters
                if (enumCategory.ToString() == "OST_DuctCurves" &&
                    element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() == null)
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_DuctCurves, BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM, BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM, BuiltInParameter.CURVE_ELEM_LENGTH,
                                BuiltInParameter.RBS_CURVE_WIDTH_PARAM, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
                }

                //Check for other ducts fittings with the same parameters
                if (enumCategory.ToString() == "OST_DuctFitting" &&
                    element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() == null)
                {
                    string elemParam01 = element.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsValueString();
                    string elemParam02 = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString();
                    string elemParam03 = element.get_Parameter(BuiltInParameter.RBS_REFERENCE_FREESIZE).AsString();
                    string elemParam04 = element.get_Parameter(BuiltInParameter.RBS_REFERENCE_OVERALLSIZE).AsString();
                    string elemParam05 = element.get_Parameter(BuiltInParameter.RBS_CALCULATED_SIZE).AsString();

                    FilteredElementCollector viewCollector = new FilteredElementCollector(doc, uidoc.ActiveView.Id);
                    List <Element>           ducts         = new FilteredElementCollector(doc, uidoc.ActiveView.Id)
                                                             .OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_DuctFitting)
                                                             .Where(a => a.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsValueString() == elemParam01)
                                                             .Where(a => a.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString() == elemParam02)
                                                             .Where(a => a.get_Parameter(BuiltInParameter.RBS_REFERENCE_FREESIZE).AsString() == elemParam03)
                                                             .Where(a => a.get_Parameter(BuiltInParameter.RBS_REFERENCE_OVERALLSIZE).AsString() == elemParam04)
                                                             .Where(a => a.get_Parameter(BuiltInParameter.RBS_CALCULATED_SIZE).AsString() == elemParam05)
                                                             .ToList();

                    foreach (Element x in ducts)
                    {
                        selectedElements.Add(x);
                        ListOfElements.Add(x);
                    }
                }


                bool boolTest = false;

                var familyTypee = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString();
                if (familyTypee.Contains("Bend"))
                {
                    boolTest = true;
                }


                bool TapTest = false;

                var familyTapType = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString();
                if (familyTapType.Contains("Tap"))
                {
                    TapTest = true;
                }


                //Check for other round ducts with the same parameters
                if (enumCategory.ToString() == "OST_DuctCurves" &&
                    element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() != null &&
                    TapTest != true)
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_DuctCurves, BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM, BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM, BuiltInParameter.CURVE_ELEM_LENGTH,
                                BuiltInParameter.RBS_CURVE_SURFACE_AREA, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM);
                }

                //Check for other rectangular fab ducts with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null &&
                    element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)?.AsValueString() != "Generic Square Bend" &&
                    TapTest != true)
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DEPTH_IN,
                                BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM);
                }


                //Check for other rectangular fab ducts fittings of angle 90 with the same parameters
                //if (enumCategory.ToString() == "OST_FabricationDuctwork"
                //    && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null
                //    && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null
                //    && element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)?.AsValueString() == "Generic Square Bend"
                //    )

                //{
                //    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN,
                //      BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM);
                //}



                //Check for other rectangular fab ducts fittings of angle 90 with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null &&
                    boolTest == true &&
                    TapTest != true
                    )
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN,
                                BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM);
                }


                //Check for other rectangular fab ducts fittings with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() != null &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null
                    )
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_ANGLE, BuiltInParameter.FABRICATION_SERVICE_PARAM,
                                BuiltInParameter.FABRICATION_PART_DEPTH_IN, BuiltInParameter.FABRICATION_PART_WIDTH_IN);
                }

                //Check for other rectangular fab ducts fittings with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() != null &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null
                    )
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_ANGLE, BuiltInParameter.FABRICATION_SERVICE_PARAM,
                                BuiltInParameter.FABRICATION_PART_DIAMETER_IN, BuiltInParameter.RBS_REFERENCE_OVERALLSIZE);
                }

                //Check for other round fab ducts with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null &&
                    TapTest != true
                    )
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DIAMETER_IN,
                                BuiltInParameter.FABRICATION_PART_SHEETMETAL_AREA, BuiltInParameter.FABRICATION_SERVICE_PARAM);
                }


                //Check for other round fab ducts with the same parameters
                if (enumCategory.ToString() == "OST_FabricationDuctwork" &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null &&
                    element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null &&
                    TapTest == true
                    )
                {
                    filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DIAMETER_IN,
                                BuiltInParameter.RBS_REFERENCE_OVERALLSIZE, BuiltInParameter.FABRICATION_SERVICE_PARAM);
                }

                selectedElements.Add(element);

                //TODO: check if element is from the right category
                OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
                Color colorSelect = MainForm.ColorSelected;

                //Split coloSelect in R,G,B to be transformed to a Revit color later
                byte r = colorSelect.R;
                byte b = colorSelect.B;
                byte g = colorSelect.G;

                //Set override properties to fill and line colors
                overrideGraphicSettings.SetProjectionFillColor(new Autodesk.Revit.DB.Color(r, g, b));
                overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(r, g, b));

                foreach (Element x in selectedElements)
                {
                    //Override color of element
                    doc.ActiveView.SetElementOverrides(x.Id, overrideGraphicSettings);
                }

                selectedElement = element;

                //Add element to the temporary list of selected elemenents
                ListOfElements.Add(element);
            }
        }
Beispiel #19
0
        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;
        }
Beispiel #20
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var color = (System.Drawing.Color)((Value.Container) args[0]).Item;
            var elem = (Element) ((Value.Container) args[1]).Item;

            var view = dynRevitSettings.Doc.ActiveView;
            var ogs = new OverrideGraphicSettings();

            if (solidFill == null)
            {
                var patternCollector = new FilteredElementCollector(dynRevitSettings.Doc.Document);
                patternCollector.OfClass(typeof(FillPatternElement));
                solidFill = patternCollector.ToElements().Cast<FillPatternElement>().First(x => x.GetFillPattern().Name == "Solid fill");
            }

            ogs.SetProjectionFillColor(new Autodesk.Revit.DB.Color(color.R, color.G, color.B));
            ogs.SetProjectionFillPatternId(solidFill.Id);
            view.SetElementOverrides(elem.Id, ogs);

            return Value.NewNumber(1);
        }
Beispiel #21
0
        /// <summary>
        /// Override the element's color in the active view.
        /// </summary>
        /// <param name="color">The color to apply to a solid fill on the element.</param>
        public Element OverrideColorInView(Color color)
        {
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            var view = DocumentManager.Instance.CurrentUIDocument.ActiveView;
            var ogs = new OverrideGraphicSettings();

            var patternCollector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
            patternCollector.OfClass(typeof(FillPatternElement));
            FillPatternElement solidFill = patternCollector.ToElements().Cast<FillPatternElement>().First(x => x.GetFillPattern().Name == "Solid fill");

            ogs.SetProjectionFillColor(new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue));
            ogs.SetProjectionFillPatternId(solidFill.Id);
            view.SetElementOverrides(this.InternalElementId, ogs);

            TransactionManager.Instance.TransactionTaskDone();
            return this;
        }
Beispiel #22
0
        /// <summary>
        /// 查看按完工和未完工标注颜色的视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Preview_Click(object sender, System.EventArgs e)
        {
            //if (Blocking.Blocks.Count == 0 || Blocking.Blocks.Where(c => c.ElementIds.Count() > 0).Count() == 0)
            //    return;

            var    doc      = m_Doc;
            string viewName = "查看完成和未完成的构件";
            var    view     = Revit_Document_Helper.GetElementByNameAs <View3D>(doc, viewName);

            if (view == null)
            {
                using (var transaction = new Transaction(doc, "EarthworkBlocking." + nameof(btn_Preview_Click)))
                {
                    transaction.Start();
                    try
                    {
                        var viewFamilyType = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).ToElements()
                                             .First(c => c.Name == "三维视图");
                        view      = View3D.CreateIsometric(doc, viewFamilyType.Id);
                        view.Name = viewName;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.RollBack();
                        ShowMessage("消息", $"视图({viewName})新建失败,错误详情:" + ex.ToString());
                    }
                }
            }
            // 渲染处理
            using (var transaction = new Transaction(doc, "EarthworkBlocking." + nameof(btn_Preview_Click)))
            {
                transaction.Start();
                //var defaultSettings = new OverrideGraphicSettings();
                //defaultSettings.SetSurfaceTransparency(50);
                //SetAllCategories(view, defaultSettings);
                foreach (var block in Blocking.Blocks)
                {
                    OverrideGraphicSettings setting = new OverrideGraphicSettings();
                    setting.SetProjectionFillPatternId(EarthworkBlockCPSettings.GetDefaultFillPatternId(doc));
                    if (block.ImplementationInfo.IsSettled)
                    {
                        setting.SetSurfaceTransparency(0);
                        setting.SetProjectionFillColor(new Autodesk.Revit.DB.Color(Blocking.ColorForSettled.R, Blocking.ColorForSettled.G, Blocking.ColorForSettled.B));
                    }
                    else
                    {
                        setting.SetSurfaceTransparency(0);
                        setting.SetProjectionFillColor(new Autodesk.Revit.DB.Color(Blocking.ColorForUnsettled.R, Blocking.ColorForUnsettled.G, Blocking.ColorForUnsettled.B));
                    }
                    foreach (var elementId in block.ElementIds)
                    {
                        //if (view.Document.GetElement(elementId) != null)
                        view.SetElementOverrides(elementId, setting);
                    }
                }
                transaction.Commit();
            }
            m_UIDoc.ActiveView = view;
            ShowDialogType     = ShowDialogType.ViewCompletion;
            DialogResult       = DialogResult.Retry;
            //SaveDataGridViewSelection();
            this.Close();
            //ShowMessage("消息", $"三维视图({viewName})更新成功");
        }
Beispiel #23
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            FilteredElementCollector elementsInView   = new FilteredElementCollector(doc);
            FillPatternElement       solidFillPattern = elementsInView.OfClass(typeof(FillPatternElement)).Cast <FillPatternElement>().First(a => a.GetFillPattern().IsSolidFill);

            List <BuiltInCategory> builtInCats = new List <BuiltInCategory>();

            builtInCats.Add(BuiltInCategory.OST_StructuralFraming);
            builtInCats.Add(BuiltInCategory.OST_Walls);
            builtInCats.Add(BuiltInCategory.OST_Floors);
            builtInCats.Add(BuiltInCategory.OST_StructuralColumns);
            builtInCats.Add(BuiltInCategory.OST_StructuralFoundation);

            ElementMulticategoryFilter filter1 = new ElementMulticategoryFilter(builtInCats);

            IList <Element> allElementsInView = new FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(filter1).WhereElementIsNotElementType().ToElements();

            var grouped = allElementsInView.GroupBy(x => x.GetTypeId());

            Random pRand = new Random();


            //TaskDialog.Show("r", grouped.First().First().Name);
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

                        #if REVIT2020
            ogs.SetSurfaceForegroundPatternId(solidFillPattern.Id);
                        #else
            ogs.SetProjectionFillPatternId(solidFillPattern.Id);
                        #endif

            using (Transaction t = new Transaction(doc, "Override Colors"))
            {
                t.Start();
                foreach (var element in grouped)
                {
                    byte iR, iG, iB;
                    iR = Convert.ToByte(pRand.Next(0, 255));
                    iG = Convert.ToByte(pRand.Next(0, 255));
                    iB = Convert.ToByte(pRand.Next(0, 255));
                    Autodesk.Revit.DB.Color pcolor = new Autodesk.Revit.DB.Color(iR, iG, iB);
                                        #if REVIT2020
                    ogs.SetSurfaceForegroundPatternColor(pcolor);
                                        #else
                    ogs.SetProjectionFillColor(pcolor);
                                        #endif
                    try
                    {
                        foreach (FamilyInstance item in element)
                        {
                            doc.ActiveView.SetElementOverrides(item.Id, ogs);
                        }
                    }
                    catch
                    {
                    }
                }

                t.Commit();
            }



            return(Result.Succeeded);
        }
Beispiel #24
0
        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) { }
        }