Esempio n. 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;
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
 public static FillPatternElement Wrap(Autodesk.Revit.DB.FillPatternElement ele, bool isRevitOwned)
 {
     return(FillPatternElement.FromExisting(ele, isRevitOwned));
 }
        /// <summary>
        /// Update the BIM with the given database records.
        /// </summary>
        ///

        public static bool UpdateBim(Document doc, List <string> doors, ref string error_message)
        //List<DBData> doors,
        {
            try
            {
                FilteredElementCollector f_collector = new FilteredElementCollector(doc).WhereElementIsNotElementType();
                IList <Element>          elements    = f_collector.OfCategory(BuiltInCategory.OST_Furniture).ToElements();

                View        activ_view = doc.ActiveView;
                Application app        = doc.Application;

                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);

                UIDocument uidoc = new UIDocument(doc);
                Color      color = new Color((byte)150, (byte)200, (byte)200);

                OverrideGraphicSettings grafics       = new OverrideGraphicSettings();
                OverrideGraphicSettings grafics_clear = new OverrideGraphicSettings();

                grafics.SetSurfaceForegroundPatternColor(color);
                grafics.SetSurfaceForegroundPatternId(solidFill.Id);

                int db_count   = Convert.ToInt32(doors[0]);
                int elem_count = 0;

                //TaskDialog.Show("target", db_count.ToString());

                using (Transaction t = new Transaction(doc))
                {
                    t.Start("db-test");

                    foreach (Element elem in elements)
                    {
                        elem_count += 1;
                        activ_view.SetElementOverrides(elem.Id, grafics_clear);
                        if (elem_count == db_count)
                        {
                            activ_view.SetElementOverrides(elem.Id, grafics);
                        }
                    }

                    uidoc.RefreshActiveView();
                    t.Commit();
                }
            }
            catch (Exception exception)
            {
                var _logModel = new LoggerView("UpdateParam Exception", exception.ToString());
                _logModel.Show();
                //TaskDialog.Show("Construction model's tools APP run faild", exception.ToString());
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
 public FillPatternElement(DB.FillPatternElement value) : base(value)
 {
 }