Beispiel #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);
        }
Beispiel #2
0
        private void removeColor(Autodesk.Revit.DB.View view)
        {
            // we need to collect all of the element Ids



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

            t.Start();

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

            var changes = _changes.Where(c => c.ChangeType != Objects.Change.ChangeTypeEnum.DeletedElement).ToList();

            IList <ElementId> ids = collectIds(changes);

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

            foreach (ElementId id in ids)
            {
                view.SetElementOverrides(id, ogs);
            }



            t.Commit();
        }
Beispiel #3
0
        public SerialOverrideGraphicSettings(RevitDB.Category category, RevitDB.OverrideGraphicSettings overrideGraphicSettings,
                                             [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document)
        {
            this.IsModified = _IsModified(overrideGraphicSettings);

            if (this.IsModified)
            {
                this._setProperties(overrideGraphicSettings, Document);
            }
        }
Beispiel #4
0
        public SerialCategoryGraphicOverrides(RevitDB.Category category, RevitView view)
        {
            RevitDoc document = view.Document;

            this.Category = new SerialCategoryId(category, document);
            this.IsHidden = view.GetCategoryHidden(category.Id);

            RevitDB.OverrideGraphicSettings overrideSettings = view.GetCategoryOverrides(category.Id);
            SerialOverrideGraphicSettings   serialOverride   = new SerialOverrideGraphicSettings(category, overrideSettings, document);

            if (serialOverride.IsModified)
            {
                this.GraphicOverride = serialOverride;
            }
        }
        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;
            }
        }
Beispiel #6
0
        public void ModifyOverrideGraphicSettings(RevitView view)
        {
            RevitDoc document = view.Document;

            RevitDB.Category category = Category.GetCategory(document);

            if (category != null)
            {
                view.SetCategoryHidden(category.Id, this.IsHidden);

                if (this.GraphicOverride != null)
                {
                    RevitDB.OverrideGraphicSettings ogs = this.GraphicOverride.ToOverrideGraphicSettings();
                    view.SetCategoryOverrides(category.Id, ogs);
                }
            }
        }
Beispiel #7
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);

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

            return(this);
        }
Beispiel #8
0
        private void _setProperties(RevitDB.OverrideGraphicSettings ogs,
                                    [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document)
        {
            if (this._IsModified(ogs))
            {
                this.IsProjectionFillPaternVisible = ogs.IsProjectionFillPatternVisible;
                this.ProjectionFillColor           = new SerialColor(ogs.ProjectionFillColor);
                this.ProjectionFillPatternId       = new SerialElementId(ogs.ProjectionFillPatternId, Document);
                this.ProjectionLineColor           = new SerialColor(ogs.ProjectionLineColor);
                this.ProjectionLinePatternId       = new SerialElementId(ogs.ProjectionLinePatternId, Document);
                this.ProjectionLineWeight          = ogs.ProjectionLineWeight;

                this.IsCutFillPaternVisible = ogs.IsCutFillPatternVisible;
                this.CutFillColor           = new SerialColor(ogs.CutFillColor);
                this.CutFillPatternId       = new SerialElementId(ogs.CutFillPatternId, Document);
                this.CutLineColor           = new SerialColor(ogs.CutLineColor);
                this.CutLinePatternId       = new SerialElementId(ogs.CutLinePatternId, Document);
                this.CutLineWeight          = ogs.CutLineWeight;

                this.Transparency = ogs.Transparency;
                this.Halftone     = ogs.Halftone;
                this.DetailLevel  = new SerialEnum(typeof(RevitDB.ViewDetailLevel), ogs.DetailLevel);
            }
        }
Beispiel #9
0
        public RevitDB.OverrideGraphicSettings ToOverrideGraphicSettings()
        {
            RevitDB.OverrideGraphicSettings ogs = new RevitDB.OverrideGraphicSettings();

            ogs.SetProjectionFillPatternVisible(this.IsProjectionFillPaternVisible);
            ogs.SetProjectionFillColor(this.ProjectionFillColor.ToColor());
            ogs.SetProjectionFillPatternId(this.ProjectionFillPatternId.ToElementId());
            ogs.SetProjectionLineColor(this.ProjectionLineColor.ToColor());
            ogs.SetProjectionLinePatternId(this.ProjectionFillPatternId.ToElementId());
            ogs.SetProjectionLineWeight(this.ProjectionLineWeight);

            ogs.SetCutFillPatternVisible(this.IsCutFillPaternVisible);
            ogs.SetCutFillColor(this.CutFillColor.ToColor());
            ogs.SetCutFillPatternId(this.CutFillPatternId.ToElementId());
            ogs.SetCutLineColor(this.CutLineColor.ToColor());
            ogs.SetCutLinePatternId(this.CutLinePatternId.ToElementId());
            ogs.SetCutLineWeight(this.CutLineWeight);

            ogs.SetSurfaceTransparency(this.Transparency);
            ogs.SetHalftone(this.Halftone);
            ogs.SetDetailLevel((RevitDB.ViewDetailLevel) this.DetailLevel.ToEnum());

            return(ogs);
        }
Beispiel #10
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();
        }
Beispiel #11
0
 public SerialOverrideGraphicSettings(RevitDB.OverrideGraphicSettings overrideGraphicSettings,
                                      [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document)
 {
     this._setProperties(overrideGraphicSettings, Document);
 }
Beispiel #12
0
        private bool _IsModified(RevitDB.OverrideGraphicSettings ogs)
        {
            bool isDefault = false;

            if (!ogs.IsProjectionFillPatternVisible)
            {
                IsModified = true;
            }
            if (ogs.ProjectionFillColor.IsValid)
            {
                IsModified = true;
            }
            if (ogs.ProjectionFillPatternId.IntegerValue != -1)
            {
                IsModified = true;
            }
            if (ogs.ProjectionFillColor.IsValid)
            {
                IsModified = true;
            }
            if (ogs.ProjectionLinePatternId.IntegerValue != -1)
            {
                IsModified = true;
            }
            if (ogs.ProjectionLineWeight != -1)
            {
                IsModified = true;
            }

            if (!ogs.IsCutFillPatternVisible)
            {
                IsModified = true;
            }
            if (ogs.CutFillColor.IsValid)
            {
                IsModified = true;
            }
            if (ogs.CutFillPatternId.IntegerValue != -1)
            {
                IsModified = true;
            }
            if (ogs.CutLineColor.IsValid)
            {
                IsModified = true;
            }
            if (ogs.CutLinePatternId.IntegerValue != -1)
            {
                IsModified = true;
            }
            if (ogs.CutLineWeight != -1)
            {
                IsModified = true;
            }

            if (ogs.Transparency != 0)
            {
                IsModified = true;
            }
            if (ogs.Halftone == true)
            {
                IsModified = true;
            }
            if (ogs.DetailLevel != RevitDB.ViewDetailLevel.Undefined)
            {
                IsModified = true;
            }

            return(IsModified);
        }
Beispiel #13
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));
        }
Beispiel #14
0
 /// <summary>
 /// Reference to the Element
 /// </summary>
 internal OverrideGraphicSettings(Autodesk.Revit.DB.OverrideGraphicSettings internalOverrideGraphicSettings)
 {
     this.InternalOverrideGraphicSettings = internalOverrideGraphicSettings;
 }
Beispiel #15
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>
        /// <returns>OverrideGraphicSettings</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")] FillPatternElement cutFillPattern,
            [DefaultArgumentAttribute("null")] FillPatternElement projectionFillPattern,
            [DefaultArgumentAttribute("null")] LinePatternElement cutLinePattern,
            [DefaultArgumentAttribute("null")] LinePatternElement projectionLinePattern,
            int cutLineWeight        = -1,
            int projectionLineWeight = -1
            )
        {
            Autodesk.Revit.DB.OverrideGraphicSettings filterSettings = new Autodesk.Revit.DB.OverrideGraphicSettings();

            // Apply Colors
            if (cutFillColor != null)
            {
                filterSettings.SetCutFillColor(ToRevitColor(cutFillColor));
            }
            if (projectionFillColor != null)
            {
                filterSettings.SetProjectionFillColor(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.SetCutFillPatternId(cutFillPattern.Id);
            }
            if (projectionFillPattern != null)
            {
                filterSettings.SetProjectionFillPatternId(projectionFillPattern.Id);
            }
            if (cutLinePattern != null)
            {
                filterSettings.SetCutLinePatternId(cutLinePattern.Id);
            }
            if (projectionLinePattern != null)
            {
                filterSettings.SetProjectionLinePatternId(projectionLinePattern.Id);
            }

            return(new OverrideGraphicSettings(filterSettings));
        }