Exemple #1
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 Autodesk.Revit.DB.OverrideGraphicSettings();

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

            patternCollector.OfClass(typeof(Autodesk.Revit.DB.FillPatternElement));
            Autodesk.Revit.DB.FillPatternElement solidFill = patternCollector.ToElements().Cast <Autodesk.Revit.DB.FillPatternElement>().First(x => x.GetFillPattern().IsSolidFill);

            var overrideColor = new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue);

            // the old functions SetProjectionFillColor and SetProjectionFillPatternId,
            // are obsoleted and suggested by the documentation that will be removed and
            // replaced by SetSurfaceForegroundPatternColor and SetSurfaceForegroundPatternId.

            ogs.SetSurfaceForegroundPatternColor(overrideColor);
            ogs.SetSurfaceForegroundPatternId(solidFill.Id);
            ogs.SetProjectionLineColor(overrideColor);
            view.SetElementOverrides(InternalElementId, ogs);
            TransactionManager.Instance.TransactionTaskDone();

            return(this);
        }
        private void RunSetColor(Autodesk.Revit.DB.View view, IList <ElementId> elemIds)
        {
            DisableTemperaryMode();
            _uidoc.Selection.SetElementIds(elemIds);
            _uidoc.ShowElements(elemIds);

            var color = viewModel.RvtColorElement;

            try
            {
                var ogs = new Autodesk.Revit.DB.OverrideGraphicSettings();

                var patternCollector = new FilteredElementCollector(_doc.ActiveView.Document);
                patternCollector.OfClass(typeof(Autodesk.Revit.DB.FillPatternElement));
                Autodesk.Revit.DB.FillPatternElement solidFill = patternCollector.ToElements().Cast <Autodesk.Revit.DB.FillPatternElement>().First(x => x.GetFillPattern().IsSolidFill);
#if REVIT2018
                ogs.SetProjectionFillColor(color);
                ogs.SetProjectionFillPatternId(solidFill.Id);
                ogs.SetProjectionLineColor(color);
                ogs.SetCutFillColor(color);
                ogs.SetCutFillPatternId(solidFill.Id);
                ogs.SetCutLineColor(color);
#else
                ogs.SetSurfaceForegroundPatternColor(color);
                ogs.SetSurfaceForegroundPatternId(solidFill.Id);
                ogs.SetProjectionLineColor(color);
                ogs.SetCutForegroundPatternColor(color);
                ogs.SetCutForegroundPatternId(solidFill.Id);
                ogs.SetCutLineColor(color);
#endif

                using (Transaction t = new Transaction(_doc, "Set Element Override"))
                {
                    t.Start();
                    foreach (var id in elemIds)
                    {
                        _doc.ActiveView.SetElementOverrides(id, ogs);
                    }

                    t.Commit();
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #3
0
        private void performColor()
        {
            // we need to collect all of the element Ids



            Transaction t = new Transaction(_uiDoc.Document, "Color Changed Elements");

            t.Start();

            if (!_isResetting)
            {
                _viewsColored[_uiDoc.ActiveGraphicalView.Id.IntegerValue] = true;
            }

            Autodesk.Revit.DB.Color overrideColor = new Autodesk.Revit.DB.Color(0, 0, 0);

            // group changes by type...
            var grouped = _changes.GroupBy(c => c.ChangeType).ToDictionary(c => c.Key, c => c.ToList());

            var list = grouped.Keys.ToList();

            if (list.Contains(Objects.Change.ChangeTypeEnum.DeletedElement))
            {
                list.Remove(Objects.Change.ChangeTypeEnum.DeletedElement);
            }
            if (list.Count == 0)
            {
                MessageBox.Show("No color-able change types!");
                t.RollBack();
                return;
            }
            UI.ColorChoiceForm choice = new UI.ColorChoiceForm(list);
            if (choice.ShowDialog(this) != DialogResult.OK)
            {
                t.RollBack();
                return;
            }

            foreach (var group in grouped)
            {
                if (group.Key == Objects.Change.ChangeTypeEnum.DeletedElement)
                {
                    continue;                                                            // can't
                }
                if (choice.ChangeTypes.Contains(group.Key) == false)
                {
                    continue;                                                  // not selected.
                }
                var ogs = new Autodesk.Revit.DB.OverrideGraphicSettings();

                var patternCollector = new FilteredElementCollector(_uiDoc.Document);
                patternCollector.OfClass(typeof(Autodesk.Revit.DB.FillPatternElement));
                Autodesk.Revit.DB.FillPatternElement solidFill = patternCollector.ToElements().Cast <Autodesk.Revit.DB.FillPatternElement>().First(x => x.GetFillPattern().IsSolidFill);

                IList <ElementId> ids = collectIds(group.Value);

                overrideColor = Utilities.Settings.GetColor(group.Key);


#if REVIT2015 || REVIT2016 || REVIT2017 || REVIT2018
                ogs.SetProjectionFillColor(overrideColor);
                ogs.SetProjectionFillPatternId(solidFill.Id);
                ogs.SetProjectionLineColor(overrideColor);
                ogs.SetCutFillColor(overrideColor);
                ogs.SetCutFillPatternId(solidFill.Id);
                ogs.SetCutLineColor(overrideColor);
#else
                ogs.SetSurfaceForegroundPatternColor(overrideColor);
                ogs.SetSurfaceForegroundPatternId(solidFill.Id);
                ogs.SetProjectionLineColor(overrideColor);
                ogs.SetCutForegroundPatternColor(overrideColor);
                ogs.SetCutForegroundPatternId(solidFill.Id);
                ogs.SetCutLineColor(overrideColor);
#endif
                foreach (ElementId id in ids)
                {
                    _uiDoc.ActiveGraphicalView.SetElementOverrides(id, ogs);
                }
            }

            t.Commit();
        }
Exemple #4
0
        /// <summary>
        /// Create a OverrideGraphicSettings Element.
        /// </summary>
        /// <param name="cutFillColor">Fill color</param>
        /// <param name="projectionFillColor">Projection color</param>
        /// <param name="cutLineColor">Cut line color</param>
        /// <param name="projectionLineColor">Projection line color</param>
        /// <param name="cutLineWeight">Cut line weight</param>
        /// <param name="projectionLineWeight">Projection line weight</param>
        /// <param name="cutFillPattern">Cut fill pattern</param>
        /// <param name="projectionFillPattern">Projection fill pattern</param>
        /// <param name="cutLinePattern">Cut line pattern</param>
        /// <param name="projectionLinePattern">Projection line pattern</param>
        /// <param name="transparency">Transparency as integer between 1-100.</param>
        /// <param name="detailLevel">Detail Level setting, ex: Coarse, Fine etc.</param>
        /// <param name="halftone">Halftone. True = halftone.</param>
        /// <returns name="overrides">Override Graphic Settings</returns>
        public static OverrideGraphicSettings ByProperties(
            [DefaultArgumentAttribute("null")] DSCore.Color cutFillColor,
            [DefaultArgumentAttribute("null")] DSCore.Color projectionFillColor,
            [DefaultArgumentAttribute("null")] DSCore.Color cutLineColor,
            [DefaultArgumentAttribute("null")] DSCore.Color projectionLineColor,
            [DefaultArgumentAttribute("null")] Revit.Elements.FillPatternElement cutFillPattern,
            [DefaultArgumentAttribute("null")] Revit.Elements.FillPatternElement projectionFillPattern,
            [DefaultArgumentAttribute("null")] Revit.Elements.LinePatternElement cutLinePattern,
            [DefaultArgumentAttribute("null")] Revit.Elements.LinePatternElement projectionLinePattern,
            int cutLineWeight        = -1,
            int projectionLineWeight = -1,
            int transparency         = -1,
            string detailLevel       = "Undefined",
            bool halftone            = false
            )
        {
            Autodesk.Revit.DB.OverrideGraphicSettings filterSettings = new Autodesk.Revit.DB.OverrideGraphicSettings();

            // the old functions SetCutFillColor, SetCutFillPatternId,
            // SetProjectionFillColor and SetProjectionFillPatternId,
            // are obsoleted and suggested by the documentation that will be removed and
            // replaced by SetCutForegroundPatternColor, SetCutForegroundPatternId,
            // SetSurfaceForegroundPatternColor, SetSurfaceForegroundPatternId.

            // Apply Colors
            if (cutFillColor != null)
            {
                filterSettings.SetCutForegroundPatternColor(ToRevitColor(cutFillColor));
            }
            if (projectionFillColor != null)
            {
                filterSettings.SetSurfaceForegroundPatternColor(ToRevitColor(projectionFillColor));
            }
            if (cutLineColor != null)
            {
                filterSettings.SetCutLineColor(ToRevitColor(cutLineColor));
            }
            if (projectionLineColor != null)
            {
                filterSettings.SetProjectionLineColor(ToRevitColor(projectionLineColor));
            }

            // Apply Lineweight
            if (cutLineWeight != -1)
            {
                filterSettings.SetCutLineWeight(cutLineWeight);
            }
            if (projectionLineWeight != -1)
            {
                filterSettings.SetProjectionLineWeight(projectionLineWeight);
            }

            // Apply Patterns
            if (cutFillPattern != null)
            {
                filterSettings.SetCutForegroundPatternId(cutFillPattern.InternalElement.Id);
            }
            if (projectionFillPattern != null)
            {
                filterSettings.SetSurfaceForegroundPatternId(projectionFillPattern.InternalElement.Id);
            }
            if (cutLinePattern != null)
            {
                filterSettings.SetCutLinePatternId(cutLinePattern.InternalElement.Id);
            }
            if (projectionLinePattern != null)
            {
                filterSettings.SetProjectionLinePatternId(projectionLinePattern.InternalElement.Id);
            }

            // Apply transparency, detail level and halftone
            if (transparency != -1)
            {
                filterSettings.SetSurfaceTransparency(transparency);
            }
            if (halftone)
            {
                filterSettings.SetHalftone(halftone);
            }
            filterSettings.SetDetailLevel((Autodesk.Revit.DB.ViewDetailLevel)System.Enum.Parse(typeof(Autodesk.Revit.DB.ViewDetailLevel), detailLevel));

            return(new OverrideGraphicSettings(filterSettings));
        }