public void Execute(UIApplication uiapp)
    {
        //IL_0001: Unknown result type (might be due to invalid IL or missing references)
        //IL_0002: Unknown result type (might be due to invalid IL or missing references)
        //IL_0007: Unknown result type (might be due to invalid IL or missing references)
        //IL_000c: Unknown result type (might be due to invalid IL or missing references)
        //IL_000d: Unknown result type (might be due to invalid IL or missing references)
        //IL_000e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0013: Unknown result type (might be due to invalid IL or missing references)
        //IL_0014: Unknown result type (might be due to invalid IL or missing references)
        //IL_0015: Unknown result type (might be due to invalid IL or missing references)
        //IL_001a: Unknown result type (might be due to invalid IL or missing references)
        //IL_001b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0020: Unknown result type (might be due to invalid IL or missing references)
        //IL_0021: Unknown result type (might be due to invalid IL or missing references)
        //IL_0022: Unknown result type (might be due to invalid IL or missing references)
        //IL_0027: Unknown result type (might be due to invalid IL or missing references)
        //IL_002c: Unknown result type (might be due to invalid IL or missing references)
        //IL_002e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0037: Unknown result type (might be due to invalid IL or missing references)
        //IL_0038: Unknown result type (might be due to invalid IL or missing references)
        //IL_003d: Unknown result type (might be due to invalid IL or missing references)
        //IL_003f: Unknown result type (might be due to invalid IL or missing references)
        //IL_0046: Unknown result type (might be due to invalid IL or missing references)
        //IL_005a: Unknown result type (might be due to invalid IL or missing references)
        //IL_005f: Unknown result type (might be due to invalid IL or missing references)
        //IL_0062: Unknown result type (might be due to invalid IL or missing references)
        //IL_0063: Unknown result type (might be due to invalid IL or missing references)
        //IL_0065: Unknown result type (might be due to invalid IL or missing references)
        //IL_006a: Unknown result type (might be due to invalid IL or missing references)
        //IL_008a: Unknown result type (might be due to invalid IL or missing references)
        //IL_008c: Unknown result type (might be due to invalid IL or missing references)
        Document   document           = uiapp.get_ActiveUIDocument().get_Document();
        UIDocument activeUIDocument   = uiapp.get_ActiveUIDocument();
        View       activeView         = document.get_ActiveView();
        OverrideGraphicSettings  val  = new OverrideGraphicSettings();
        FilteredElementCollector val2 = new FilteredElementCollector(document).WhereElementIsNotElementType();
        IList <Element>          list = val2.ToElements();
        Transaction val3 = new Transaction(document);

        val3.Start("ViewResetElementOverride");
        foreach (Element item in list)
        {
            activeView.SetElementOverrides(item.get_Id(), val);
        }
        val3.Commit();
    }
        /// <summary>
        /// Save an element on a temporary list and override its color
        /// </summary>
        public static void AddToSelection(bool duplicated)
        {
            selectedElements.Clear();

            var filterS = new SelectionFilter();

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

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

                if (duplicated)
                {
                    selectedElements.AddRange(GetallElementsDuplicated(element));
                }
                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 g = colorSelect.G;
                byte b = colorSelect.B;


                #if REVIT2020
                OverrideElemtColor.Graphics20192020(doc, ref overrideGraphicSettings, r, g, b);
                #elif REVIT2019
                OverrideElemtColor.Graphics20172020(doc, ref overrideGraphicSettings, r, g, b);
                #endif


                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);
            }
        }
示例#3
0
        public void ChangeColor()
        {
            Document   doc              = this.ActiveUIDocument.Document;
            UIDocument uidoc            = this.ActiveUIDocument;
            Element    solidFill        = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Where(q => q.Name.Contains("單色填滿")).First();
            ElementId  id               = uidoc.Selection.PickObject(ObjectType.Element, "Select an element").ElementId;
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

            ogs.SetProjectionLineColor(new Color(0, 255, 0));
            ogs.SetProjectionFillPatternId(solidFill.Id);
            using (Transaction t = new Transaction(doc, "Set Element Override"))
            {
                t.Start();
                doc.ActiveView.SetElementOverrides(id, ogs);
                t.Commit();
            }
        }
示例#4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiapp = commandData.Application;
            _uidoc = _uiapp.ActiveUIDocument;
            _doc   = _uidoc.Document;

            try
            {
                // Get list of all CAD files
                IList <ImportInstance> cadFileLinksList = GetAllCADFiles(_doc);
                if (cadFileLinksList.Count == 0)
                {
                    return(Result.Cancelled);
                }

                // Get list of all views
                IList <ViewPlan> viewPlanList = GetAllStructuralPlans(_doc, true);
                if (viewPlanList.Count == 0)
                {
                    return(Result.Cancelled);
                }

                foreach (ViewPlan view in viewPlanList)                  // Loop through each view
                {
                    foreach (ImportInstance cadFile in cadFileLinksList) // On each view, loop through each CAD file
                    {
                        OverrideGraphicSettings ogs = view.GetElementOverrides(cadFile.Id);
                        //Set Halftone Element
                        using (Transaction tx = new Transaction(_doc))
                        {
                            tx.Start("Undo Halftone");
                            ogs.SetHalftone(false);
                            view.SetElementOverrides(cadFile.Id, ogs);
                            tx.Commit();
                        }
                    }
                }
                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
示例#5
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();
        }
示例#6
0
        /// <summary>
        ///   Metodo che ripristina il colore originale dei Pannelli
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="uiapp">L'oggetto Applicazione di Revit</param>m>
        ///
        public void CancelAllChanges(UIApplication uiapp)
        {
            // Dichiara e inizializza un OverrideGraphicSettings
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

            using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document))
            {
                trans.Start("Reset Color");

                foreach (Element ele in _elements)
                {
                    // Fa l'override delle impostazioni grafiche dell'elemento
                    uiapp.ActiveUIDocument.Document.ActiveView.SetElementOverrides(ele.Id, ogs);
                }

                trans.Commit();
            }
        }
示例#7
0
        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);
        }
        private static void createSheetsAndViews(Document doc, IEnumerable <VisualizationDeliverable> visualizationDeliverables, BoundingBoxXYZ modelExtents)
        {
            //Setup
            string _titleblockName    = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            int    _demandViewScale   = 120;
            int    _combinedViewScale = 120;
            int    _capacityViewScale = 120;

            SheetCreator _sheetCreator = new SheetCreator(doc);

            OverrideGraphicSettings _modelElementsOgs = getModelOgs();

            Level _levelAbove = null;

            foreach (VisualizationDeliverable _visualizationDeliverable in visualizationDeliverables)
            {
                BoundingBoxXYZ _levelBounds = new BoundingBoxXYZ();
                _levelBounds.Min = new XYZ(modelExtents.Min.X, modelExtents.Min.Y, _visualizationDeliverable.Level.Elevation);

                if (_levelAbove == null)
                {
                    _levelBounds.Max = new XYZ(modelExtents.Max.X, modelExtents.Max.Y, modelExtents.Max.Z);
                    _levelAbove      = _visualizationDeliverable.Level;
                }
                else
                {
                    _levelBounds.Max = new XYZ(modelExtents.Max.X, modelExtents.Max.Y, _levelAbove.Elevation);
                }

                //View Creation
                BoundedViewCreator _boundedViewCreator = new BoundedViewCreator(_visualizationDeliverable.Level, null, _levelBounds);

                string    _viewName  = _boundedViewCreator.GetViewName("Visualization", string.Empty);
                ViewSheet _viewSheet = _sheetCreator.CreateSheet(_titleblockName, _viewName, _viewName);

                _visualizationDeliverable.Sheet        = _viewSheet;
                _visualizationDeliverable.DemandView   = createView3D("Demand", _boundedViewCreator, _demandViewScale, _modelElementsOgs);
                _visualizationDeliverable.CombinedView = createView3D("Combined", _boundedViewCreator, _combinedViewScale, _modelElementsOgs);
                _visualizationDeliverable.CapacityView = createView3D("Capacity", _boundedViewCreator, _capacityViewScale, _modelElementsOgs);

                _levelAbove = _visualizationDeliverable.Level;
            }
        }
        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;
        }
示例#10
0
        private void DrawAxisPerpendicularToDirections(Document doc, XYZ origin, XYZ dir1, XYZ dir2, double length, Color color)
        {
            XYZ         pntCenter  = origin;
            XYZ         cross      = dir2.CrossProduct(dir1);
            XYZ         pntEnd     = pntCenter + cross.Multiply(length / 304.8);
            Plane       perpPlane  = Plane.CreateByThreePoints(pntCenter, pntEnd, dir1);
            SketchPlane perpSplane = SketchPlane.Create(doc, perpPlane);
            Line        line2      = Autodesk.Revit.DB.Line.CreateBound(pntCenter, pntEnd);
            ModelLine   perpLine   = doc.Create.NewModelCurve(line2, perpSplane) as ModelLine;

            try
            {
                OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                ogs.SetProjectionLineColor(color); // or other here
                doc.ActiveView.SetElementOverrides(perpLine.Id, ogs);
            }
            catch
            {
            }
        }
示例#11
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();
            }
        }
示例#12
0
        private static void CreateDirectShape(Document doc, Solid solid, Color color, string paramValue)
        {
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();
            //ogs.SetProjectionFillColor(color); //new Color(0,255,0)
            //ogs.SetProjectionFillPatternId(new ElementId(4));
            //ogs.SetProjectionFillPatternVisible(true);

            // create direct shape and assign the sphere shape
            DirectShape dsmax = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));

            dsmax.ApplicationId     = "ApplicationID";
            dsmax.ApplicationDataId = "ApplicationDataId";

            dsmax.SetShape(new GeometryObject[] { solid });
            doc.ActiveView.SetElementOverrides(dsmax.Id, ogs);

            Parameter parameter = dsmax.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);

            parameter.Set(paramValue);
        }
示例#13
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));
        }
示例#14
0
        public static void ResetView()
        {
            View activeView = RevitTools.Doc.ActiveView;

            FilteredElementCollector coll = new FilteredElementCollector(RevitTools.Doc, activeView.Id).WhereElementIsViewIndependent().WhereElementIsNotElementType();
            var output = coll.ToElementIds();
            OverrideGraphicSettings clean = new OverrideGraphicSettings();

            foreach (var element in output)
            {
                activeView.SetElementOverrides(element, clean);
            }



            if (activeView.IsTemporaryHideIsolateActive())
            {
                TemporaryViewMode tempView = TemporaryViewMode.TemporaryHideIsolate;
                activeView.DisableTemporaryViewMode(tempView);
            }
        }
示例#15
0
        private void SetElementTransparency(View3D view3d, Dictionary <int, Element> elementDictionary)
        {
            try
            {
                this.toolStripProgressBar1.Visible = true;
                this.toolStripStatusLabel1.Text    = "Setting Transparency of Elements...";
                Application.DoEvents();
                System.Threading.Thread.Sleep(1000);

                OverrideGraphicSettings settings = new OverrideGraphicSettings();
                settings.SetSurfaceTransparency(70);
                settings.SetHalftone(true);

                BoundingBoxXYZ boundingBox                      = view3d.GetSectionBox();
                Outline        outline                          = new Outline(boundingBox.Min, boundingBox.Max);
                BoundingBoxIntersectsFilter filter              = new BoundingBoxIntersectsFilter(outline);
                FilteredElementCollector    collector           = new FilteredElementCollector(m_doc);
                IList <Element>             boundingBoxElements = collector.WherePasses(filter).ToElements();

                this.toolStripProgressBar1.Maximum = boundingBoxElements.Count;
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.ProgressBar.Refresh();

                foreach (Element element in boundingBoxElements)
                {
                    if (elementDictionary.ContainsKey(element.Id.IntegerValue))
                    {
                        continue;
                    }
                    view3d.SetElementOverrides(element.Id, settings);
                    this.toolStripProgressBar1.PerformStep();
                }
                this.toolStripProgressBar1.Visible = false;
                this.toolStripStatusLabel1.Text    = "Ready";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a 3DView named " + selectedView + "\n" + ex.Message, "CommandForm:Create3DView", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#16
0
        //改变选中实例的颜色(被选中的族实例要已经赋予了材质,这个方法才起作用)
        private Color changeProfileColor(FamilyInstance familyInstance, ExternalCommandData commandData)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;           //取得当前活动文档

            //初试颜色
            Material materialOrigin = uiDoc.Document.GetElement(familyInstance.GetMaterialIds(false).First()) as Material;
            Color    colorOrigin    = materialOrigin.Color;

            //改变选中实例的线的颜色
            OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();

            overrideGraphicSettings = uiDoc.Document.ActiveView.GetElementOverrides(familyInstance.Id);

            Color color = new Color(255, 0, 0);

            overrideGraphicSettings.SetProjectionLineColor(color);
            //在当前视图下设置,其它视图保持原来的
            uiDoc.Document.ActiveView.SetElementOverrides(familyInstance.Id, overrideGraphicSettings);
            uiDoc.Document.Regenerate();

            return(colorOrigin);
        }
        private void SetCutPatternSettings(View view, BuiltInCategory buildInCategory, Autodesk.Revit.DB.Color backgroundColor, FillPatternElement foregroundFillPattern)
        {
            ElementId categoryId = new ElementId(buildInCategory);

            OverrideGraphicSettings ogSettings = view.GetCategoryOverrides(categoryId);

            if ((ogSettings == null) || (!ogSettings.IsValidObject))
            {
                Utils.ShowWarningMessageBox(string.Format("Graphic overrides category '{0}' is not found or is not valid", buildInCategory.ToString()));
                return;
            }

            if (!(view.IsCategoryOverridable(categoryId)))
            {
                Utils.ShowWarningMessageBox(string.Format("Graphic overrides category '{0}' is not overridable", buildInCategory.ToString()));
                return;
            }

            ogSettings.SetCutBackgroundPatternColor(backgroundColor);
            ogSettings.SetCutForegroundPatternId(foregroundFillPattern.Id);
            view.SetCategoryOverrides(categoryId, ogSettings);
        }
示例#18
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);
        }
示例#19
0
        /// <summary>
        /// Reset prefix values on all elements visible on current view
        /// </summary>
        public static void reset()
        {
            var            selection = tools.uidoc.Selection.GetElementIds();
            List <Element> collector = new List <Element>();

            if (selection != null && selection.Count > 0)
            {
                foreach (var item in selection)
                {
                    collector.Add(tools.uidoc.Document.GetElement(item));
                }
            }
            else
            {
                LogicalOrFilter logicalOrFilter = new LogicalOrFilter(MEPCategories.listCat());
                collector = new FilteredElementCollector(tools.doc, tools.doc.ActiveView.Id).WherePasses(
                    logicalOrFilter).WhereElementIsNotElementType().ToElements().ToList();
            }

            using (Transaction ResetView = new Transaction(tools.uidoc.Document, "Reset view"))
            {
                ResetView.Start();
                OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
                Guid   guid         = new Guid("460e0a79-a970-4b03-95f1-ac395c070beb");
                string blankPrtnmbr = "";
                foreach (var item in collector)
                {
                    Parameter param = item.get_Parameter(guid);
                    if (param is null)
                    {
                        param = item.get_Parameter(BuiltInParameter.FABRICATION_PART_ITEM_NUMBER);
                    }
                    param.Set(blankPrtnmbr);
                }

                ResetView.Commit();
            }
        }
        private static OverrideGraphicSettings getDemandOgs(Document doc)
        {
            FillPatternElement _solidFillPattern = new FilteredElementCollector(doc)
                                                   .OfClass(typeof(FillPatternElement)).Cast <FillPatternElement>()
                                                   .FirstOrDefault(fpe => fpe.GetFillPattern().IsSolidFill);

            Color _demandColor = new Color((byte)255, (byte)0, (byte)0);
            int   _transparencyPercentForDemandCapacity = 96;

            OverrideGraphicSettings _capacityOgs = new OverrideGraphicSettings();

            _capacityOgs.SetSurfaceForegroundPatternColor(_demandColor);
            _capacityOgs.SetCutForegroundPatternColor(_demandColor);

            _capacityOgs.SetSurfaceForegroundPatternId(_solidFillPattern.Id);
            _capacityOgs.SetCutForegroundPatternId(_solidFillPattern.Id);
            _capacityOgs.SetSurfaceForegroundPatternVisible(true);
            _capacityOgs.SetCutForegroundPatternVisible(true);

            _capacityOgs.SetSurfaceTransparency(_transparencyPercentForDemandCapacity);

            return(_capacityOgs);
        }
示例#21
0
        public void ApplySettingWithoutTransaction(TEarthworkBlocking blocking, List <ElementId> elementIds)
        {
            if (elementIds == null || elementIds.Count == 0)
            {
                return;
            }
            OverrideGraphicSettings setting = GetOverrideGraphicSettings(VLConstraints.Doc);

            //元素可见性
            if (IsVisible)
            {
                VLConstraints.View3D.UnhideElements(elementIds);
            }
            else
            {
                VLConstraints.View3D.HideElements(elementIds);
            }
            //元素表面填充物配置
            foreach (var elementId in elementIds)
            {
                Revit_Helper.ApplyOverrideGraphicSettings(VLConstraints.View3D, elementId, setting);
            }
        }
示例#22
0
        /// <summary>
        /// Resets override on all elements in current view
        /// </summary>
        public static void resetView()
        {
            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();

                foreach (var item in collector.ToElements())
                {
                    if (item.IsValidObject && doc.GetElement(item.Id) != null)
                    {
                        doc.ActiveView.SetElementOverrides(item.Id, overrideGraphicSettings);
                    }
                }

                ResetView.Commit();
            }
        }
        private static void colorViews(Document doc, IEnumerable <VisualizationDeliverable> visualizationDeliverables)
        {
            OverrideGraphicSettings _capacityOgs = getCapacityOgs(doc);
            OverrideGraphicSettings _demandOgs   = getDemandOgs(doc);

            foreach (var _visualizationDeliverable in visualizationDeliverables)
            {
                IEnumerable <DirectShape> _capacityDirectShapes = getCapacityDirectShapes(_visualizationDeliverable).Where(p => p != null);
                IEnumerable <DirectShape> _demandDirectShapes   = getDemandDirectShapes(_visualizationDeliverable).Where(p => p != null);

                if (_visualizationDeliverable.CapacityView != null)
                {
                    foreach (DirectShape _directShape in _capacityDirectShapes)
                    {
                        _visualizationDeliverable.CapacityView.SetElementOverrides(_directShape.Id, _capacityOgs);
                    }
                }
                if (_visualizationDeliverable.CombinedView != null)
                {
                    foreach (DirectShape _directShape in _capacityDirectShapes)
                    {
                        _visualizationDeliverable.CombinedView.SetElementOverrides(_directShape.Id, _capacityOgs);
                    }
                    foreach (DirectShape _directShape in _demandDirectShapes)
                    {
                        _visualizationDeliverable.CombinedView.SetElementOverrides(_directShape.Id, _demandOgs);
                    }
                }
                if (_visualizationDeliverable.DemandView != null)
                {
                    foreach (DirectShape _directShape in _demandDirectShapes)
                    {
                        _visualizationDeliverable.DemandView.SetElementOverrides(_directShape.Id, _demandOgs);
                    }
                }
            }
        }
示例#24
0
        /// <summary>
        /// Resets override on all elements in current view
        /// </summary>
        public static void reset()
        {
            using (Transaction ResetView = new Transaction(tools.uidoc.Document, "Reset view"))
            {
                ResetView.Start();
                OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();

                var selection = tools.uidoc.Selection.GetElementIds();
                List <ElementId> collector = new List <ElementId>();
                if (selection != null && selection.Count > 0)
                {
                    foreach (var item in selection)
                    {
                        collector.Add(item);
                    }
                }

                else
                {
                    LogicalOrFilter logicalOrFilter = new LogicalOrFilter(MEPCategories.listCat());
                    collector = new FilteredElementCollector(tools.doc, tools.doc.ActiveView.Id).WherePasses(
                        logicalOrFilter).WhereElementIsNotElementType().ToElementIds().ToList();
                }


                foreach (var item in collector)
                {
                    if (tools.doc.GetElement(item) != null)
                    {
                        tools.doc.ActiveView.SetElementOverrides(item, overrideGraphicSettings);
                    }
                }

                ResetView.Commit();
            }
        }
        private bool ClearAllOverrides(Autodesk.Revit.DB.View activeView)
        {
            bool cleared = false;

            try
            {
                FilteredElementCollector collector  = new FilteredElementCollector(m_doc, activeView.Id);
                List <ElementId>         elementIds = collector.ToElementIds().ToList();

                OverrideGraphicSettings settings = new OverrideGraphicSettings();
                settings.SetProjectionLineColor(Autodesk.Revit.DB.Color.InvalidColorValue);
                using (Transaction trans = new Transaction(m_doc))
                {
                    try
                    {
                        trans.Start("Clear overrides");
                        foreach (ElementId eId in elementIds)
                        {
                            activeView.SetElementOverrides(eId, settings);
                        }
                        trans.Commit();
                        cleared = true;
                    }
                    catch (Exception ex)
                    {
                        trans.RollBack();
                        string message = ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to clear all overrides.\n" + ex.Message, "Clear All Overrides", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(cleared);
        }
示例#26
0
        /// <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);
            }
        }
        public static string HaveOverrides(OverrideGraphicSettings ogs)
        {
            int    invalidId = OverrideGraphicSettings.InvalidPenNumber;
            string message   = "";

            if (ogs.Halftone == true)
            {
                message += "Полутона. ";
            }

            if (ogs.ProjectionLineWeight != -1)
            {
                message += "Толщина линии проекции. ";
            }

            if (ogs.ProjectionLineColor.IsValid)
            {
                message += "Цвет линии проекции. ";
            }

            if (ogs.ProjectionLinePatternId.IntegerValue != invalidId)
            {
                message += "Тип линии проекции. ";
            }

#if R2017 || R2018
            if (ogs.IsProjectionFillPatternVisible == false)
            {
                message += "Отключена штриховка поверхности. ";
            }

            if (ogs.ProjectionFillColor.IsValid)
            {
                message += "Цвет штриховки поверхности. ";
            }

            if (ogs.ProjectionFillPatternId.IntegerValue != invalidId)
            {
                message += "Штриховка поверхности. ";
            }

            if (ogs.IsCutFillPatternVisible == false)
            {
                message += "Отключена штриховка разреза. ";
            }

            if (ogs.CutFillColor.IsValid)
            {
                message += "Цвет штриховки разреза. ";
            }

            if (ogs.CutFillPatternId.IntegerValue != invalidId)
            {
                message += "Образец штриховки разреза. ";
            }
#else
            if (ogs.IsSurfaceForegroundPatternVisible == false)
            {
                message += "Отключена штриховка передней поверхности. ";
            }
            if (ogs.IsSurfaceBackgroundPatternVisible == false)
            {
                message += "Отключена штриховка задней поверхности. ";
            }

            if (ogs.SurfaceForegroundPatternColor.IsValid)
            {
                message += "Цвет штриховки передней поверхности. ";
            }
            if (ogs.SurfaceBackgroundPatternColor.IsValid)
            {
                message += "Цвет штриховки задней поверхности. ";
            }

            if (ogs.SurfaceForegroundPatternId.IntegerValue != invalidId)
            {
                message += "Штриховка передней поверхности. ";
            }
            if (ogs.SurfaceBackgroundPatternId.IntegerValue != invalidId)
            {
                message += "Штриховка задней поверхности. ";
            }

            if (ogs.IsCutForegroundPatternVisible == false)
            {
                message += "Отключена передняя штриховка разреза. ";
            }
            if (ogs.IsCutBackgroundPatternVisible == false)
            {
                message += "Отключена задняя штриховка разреза. ";
            }

            if (ogs.CutForegroundPatternColor.IsValid)
            {
                message += "Цвет передней штриховки разреза. ";
            }
            if (ogs.CutBackgroundPatternColor.IsValid)
            {
                message += "Цвет задней штриховки разреза. ";
            }

            if (ogs.CutForegroundPatternId.IntegerValue != invalidId)
            {
                message += "Образец передней штриховки разреза. ";
            }
            if (ogs.CutBackgroundPatternId.IntegerValue != invalidId)
            {
                message += "Образец передней штриховки разреза. ";
            }
#endif

            if (ogs.Transparency != 0)
            {
                message += "Прозрачность. ";
            }


            if (ogs.CutLineWeight != -1)
            {
                message += "Толщина линии разреза. ";
            }

            if (ogs.CutLineColor.IsValid)
            {
                message += "Цвет линии разреза. ";
            }

            if (ogs.CutLinePatternId.IntegerValue != invalidId)
            {
                message += "Тип линии разреза. ";
            }

            return(message);
        }
        private bool OverrideGraphics(Autodesk.Revit.DB.View activeView)
        {
            bool result = false;

            try
            {
                //known issues: doesn't work with linked files and 3D Views
                //Creates the lists of ElementId to pass to the Projection Color Override by Element
                //those are just empty container at the moment
                FilteredElementCollector collector = new FilteredElementCollector(m_doc);

                List <ElementId> ids0 = new List <ElementId>();
                List <ElementId> ids1 = new List <ElementId>();
                List <ElementId> ids2 = new List <ElementId>();


                //It works fine for 2D views, building sections and elevations for example
                //it should work also with floor plans and even tilted Detail Views
                //but it wasn't my goal when I started
                //won't work for a 3D View
                int clip = activeView.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).AsInteger();
                //If the far clipping is not active the default depth is 10 feet and won't work correctly
                if (clip == 0)
                {
                    TaskDialog.Show("View Depth Override", "In order to use this macro far clipping must be activated.");
                }
                else
                {
                    //If the far clipping is active then the view depth can be subdivided into 3 segments:
                    //foreground (0)
                    //middle (1)
                    //background (2)
                    ids0 = IntegralCollection(activeView, 0);
                    ids1 = IntegralCollection(activeView, 1);
                    ids2 = IntegralCollection(activeView, 2);
                    //Just a check to handle some common errors, for instance not even one
                    //ElementId was found in the foreground view interval
                    if (ids0.Count == 0)
                    {
                        TaskDialog.Show("View Depth Override", "Something went wrong in the closer segment.\n\nPlease adjust the view depth to include some objects.");

                        ElementId e = new FilteredElementCollector(m_doc).OfCategory(BuiltInCategory.OST_Walls).FirstElement().Id;
                        ids0.Add(e);
                        ids1.Add(e);
                        ids2.Add(e);
                    }
                    else
                    {
                        //Again just a check to handle some common errors, in this case not even one
                        //ElementId was found in the background view interval
                        //because the view depth is too much rather then just enough to enclos
                        //the objects in the model
                        if (ids2.Count == 0)
                        {
                            TaskDialog.Show("View Depth Override", "Something went wrong in the farther segment to be overridden in Grey 192.\n\nPlease check that the view depth in the current view is just enough to include the objects you need.");
                            ElementId e = new FilteredElementCollector(m_doc).OfCategory(BuiltInCategory.OST_Walls).FirstElement().Id;
                            ids2.Add(e);
                            ids1.Add(e);
                        }
                    }
                }
                //Begins the transaction to override the elements
                using (Transaction t = new Transaction(m_doc, "View Depth Override"))
                {
                    t.Start();
                    while (ids0.Count > 0)
                    {
                        //Stores the color for the foreground
                        OverrideGraphicSettings gSettings = activeView.GetElementOverrides(ids0.First());
                        Color Color0 = gSettings.ProjectionLineColor;

                        if (ids1.Count != 0)
                        {
                            OverrideGraphicSettings gSettings1 = new OverrideGraphicSettings();
                            gSettings1.SetProjectionLineColor(new Color((byte)128, (byte)128, (byte)128));

                            foreach (ElementId eId in ids1)
                            {
                                activeView.SetElementOverrides(eId, gSettings1);
                            }
                        }
                        else
                        {
                            //Just a precaution, not sure it is really necessary
                            TaskDialog.Show("View Depth Override", "Something went wrong in the middle segment to be overridden in Grey 128.\n\nPlease check that the view depth in the current view is just enough to include the objects you need.");
                            break;
                        }
                        if (ids2.Count != 0)
                        {
                            OverrideGraphicSettings gSettings2 = new OverrideGraphicSettings();
                            gSettings2.SetProjectionLineColor(new Color((byte)192, (byte)192, (byte)192));

                            foreach (ElementId eId in ids2)
                            {
                                activeView.SetElementOverrides(eId, gSettings2);
                            }
                        }
                        else
                        {
                            //Overrides the background segment
                            TaskDialog.Show("View Depth Override", "Something went wrong in the farther segment to be overridden in Grey 192.\n\nPlease check that the view depth in the current view is just enough to include the objects you need.");
                            break;
                        }
                        //Resets the foreground color in case of objects overlapping
                        //foreground and middle segment
                        gSettings.SetProjectionLineColor(Color0);
                        foreach (ElementId eId in ids0)
                        {
                            activeView.SetElementOverrides(eId, gSettings);
                        }
                        break;
                    }
                    m_doc.Regenerate();
                    m_app.ActiveUIDocument.RefreshActiveView();
                    t.Commit();
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to override graphics.\n" + ex.Message, "Override Graphics - " + activeView.Name, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
示例#29
0
        private static Result createDeliverableSheets(UIDocument uiDoc)
        {
            //ToDo: these might be good as settings in a future UI
            string _titleblockName = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            //string _elementName = "C-2"; // "EllisShore_LumberWithClamps";
            //
            //int _3dViewScale = 48;
            //XYZ _3dViewportCenter = new XYZ(2.21129429621462, 0.656294714474886, 0);
            //
            //int _sectionViewScale = 32;
            //XYZ _sectionViewportCenter = new XYZ(0.7791340191012, 1.72774616204266, 0);

            int _floorplanViewScale      = 20;
            XYZ _floorplanViewportCenter = new XYZ(1.13879414318027, 1.16675126090371, -0.025);

            XYZ _scheduleBottomLeft = new XYZ(1.9435380772204, 2.43263378194158, 0);

            Document _doc = uiDoc.Document;

            //Get a BoundedView3DDefinition for each Level - Scope Box in the project
            var _levels = Getters.GetLevels(_doc);

            var _scopeBoxes = Getters.GetScopeBoxes(_doc);

            var    _boundedViewCreators = new List <BoundedViewCreator>();
            double _extraExtents        = 0.5;

            foreach (Level _level in _levels)
            {
                Level _levelAbove = _levels.FirstOrDefault(p => p.Elevation > _level.Elevation);
                if (_levelAbove == null)
                {
                    continue;
                }

                foreach (Element _scopeBox in _scopeBoxes)
                {
                    BoundingBoxXYZ _scopeBoxBounds = _scopeBox.get_BoundingBox(null);
                    BoundingBoxXYZ _viewBounds     = new BoundingBoxXYZ
                    {
                        Min = new XYZ(
                            _scopeBoxBounds.Min.X - _extraExtents,
                            _scopeBoxBounds.Min.Y - _extraExtents,
                            _level.Elevation - _extraExtents),
                        Max = new XYZ(
                            _scopeBoxBounds.Max.X + _extraExtents,
                            _scopeBoxBounds.Max.Y + _extraExtents,
                            _levelAbove.Elevation + _extraExtents)
                    };

                    _boundedViewCreators.Add(new BoundedViewCreator(_level, _scopeBox, _viewBounds));
                }
            }

            //Generate Views, set their Boundaries & Names, Adjust Visiblity Graphics
            OverrideGraphicSettings _70Transparent = new OverrideGraphicSettings();

            _70Transparent.SetSurfaceTransparency(70);

            List <Tuple <ElementId, string, List <View> > > _createdSheetIdViewIdSets = new List <Tuple <ElementId, string, List <View> > >();

            foreach (var _boundedViewCreator in _boundedViewCreators)
            {
                SheetCreator    _sheetCreator    = new SheetCreator(_doc);
                ScheduleCreator _scheduleCreator = new ScheduleCreator(_doc);

                //Create Sheet
                string    _pourName  = _boundedViewCreator.GetViewName(string.Empty);
                ViewSheet _sheetView = _sheetCreator.CreateSheet(_titleblockName, _pourName, _pourName);

                ////Create 3D View
                //View3D _3DView = _boundedViewCreator.CreateView3D(_3dViewScale);
                //_3DView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_3DView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //Create Floorplan View
                ViewPlan _floorPlanView = _boundedViewCreator.CreateViewPlan(_floorplanViewScale);
                _floorPlanView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                _floorPlanView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                ////Create Section View
                //ViewSection _sectionView = _boundedViewCreator.CreateViewSection(_sectionViewScale);
                //_sectionView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_sectionView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //ToDo: get necessary parameters into shared parameters, so that they are visible in Project
                // //Create Schedule
                // ViewSchedule _viewSchedule = _scheduleCreator.CreateSchedule(false, _pourName + " Shoring");
                // ScheduleField _comments = _scheduleCreator.AppendField(_viewSchedule, "Comments"); //Pour Name
                // ScheduleField _count = _scheduleCreator.AppendField(_viewSchedule, "Count");
                // ScheduleField _familyAndType = _scheduleCreator.AppendField(_viewSchedule, "Family and Type");
                // //ScheduleField _material = _scheduleCreator.AppendField(_viewSchedule, "Material");
                // //ScheduleField _clampSpacing = _scheduleCreator.AppendField(_viewSchedule, "Clamp Spacing");
                // //ScheduleField _lowerShoreLength = _scheduleCreator.AppendField(_viewSchedule, "Lower Shore Length");
                // //ScheduleField _upperShoreLength = _scheduleCreator.AppendField(_viewSchedule, "Upper Shore Length");
                // ScheduleField _height = _scheduleCreator.AppendField(_viewSchedule, "Height");
                // ScheduleField _clearShoreHeight = _scheduleCreator.AppendField(_viewSchedule, "Clear Shore Height"); //Total Shore Length
                // //ScheduleField _shoreLength = _scheduleCreator.AppendField(_viewSchedule, "Shore Overlap");
                // //ScheduleField _lumberWidth = _scheduleCreator.AppendField(_viewSchedule, "Lumber Width");
                // //ScheduleField _lumberThickness = _scheduleCreator.AppendField(_viewSchedule, "Lumber Thickness");
                // ScheduleField _loadCapacity = _scheduleCreator.AppendField(_viewSchedule, "Load Capacity"); //Safe Working Load
                //
                // _scheduleCreator.AppendSortField(_viewSchedule, _familyAndType);
                // //_scheduleCreator.AppendSortField(_viewSchedule, _lowerShoreLength);
                // //_scheduleCreator.AppendSortField(_viewSchedule, _upperShoreLength);
                // _scheduleCreator.AppendSortField(_viewSchedule, _clearShoreHeight);
                //
                // _scheduleCreator.AppendFilter(_viewSchedule, _comments, ScheduleFilterType.Equal, _pourName);
                //
                // ScheduleSheetInstance _scheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _sheetView.Id, _viewSchedule.Id, _scheduleBottomLeft);

                _createdSheetIdViewIdSets.Add(new Tuple <ElementId, string, List <View> >(
                                                  _sheetView.Id,
                                                  _pourName,
                                                  new List <View> { /*_3DView,*/
                    _floorPlanView,                                 /*_sectionView*/
                }
                                                  ));
            }

            _doc.Regenerate();

            foreach (var _createdSheetIdViewIdSet in _createdSheetIdViewIdSets)
            {
                foreach (View _view in _createdSheetIdViewIdSet.Item3)
                {
                    if (_view == null)
                    {
                        continue;
                    }

                    //if (_view is View3D) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _3dViewportCenter);
                    else if (_view is ViewPlan)
                    {
                        DimensionCreator.CreateDimensions(_view, _createdSheetIdViewIdSet.Item2);
                        Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _floorplanViewportCenter);
                    }
                    //else if (_view is ViewSection) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _sectionViewportCenter);
                }
            }

            return(Result.Succeeded);
        }
示例#30
0
        /// <summary>
        /// Alternative implementation published January 23, 2015:
        /// http://thebuildingcoder.typepad.com/blog/2015/01/getting-the-wall-elevation-profile.html
        /// </summary>
        public Result Execute2(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;

            Autodesk.Revit.Creation.Application creapp
                = app.Create;

            Autodesk.Revit.Creation.Document credoc
                = doc.Create;

            Reference r = uidoc.Selection.PickObject(
                ObjectType.Element, "Select a wall");

            Element e = uidoc.Document.GetElement(r);

            Wall wall = e as Wall;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Wall Profile");

                // Get the external wall face for the profile

                IList <Reference> sideFaces
                    = HostObjectUtils.GetSideFaces(wall,
                                                   ShellLayerType.Exterior);

                Element e2 = doc.GetElement(sideFaces[0]);

                Face face = e2.GetGeometryObjectFromReference(
                    sideFaces[0]) as Face;

                // The normal of the wall external face.

                XYZ normal = face.ComputeNormal(new UV(0, 0));

                // Offset curve copies for visibility.

                Transform offset = Transform.CreateTranslation(
                    5 * normal);

                // If the curve loop direction is counter-
                // clockwise, change its color to RED.

                Color colorRed = new Color(255, 0, 0);

                // Get edge loops as curve loops.

                IList <CurveLoop> curveLoops
                    = face.GetEdgesAsCurveLoops();

                // ExporterIFCUtils class can also be used for
                // non-IFC purposes. The SortCurveLoops method
                // sorts curve loops (edge loops) so that the
                // outer loops come first.

                IList <IList <CurveLoop> > curveLoopLoop
                    = ExporterIFCUtils.SortCurveLoops(
                          curveLoops);

                foreach (IList <CurveLoop> curveLoops2
                         in curveLoopLoop)
                {
                    foreach (CurveLoop curveLoop2 in curveLoops2)
                    {
                        // Check if curve loop is counter-clockwise.

                        bool isCCW = curveLoop2.IsCounterclockwise(
                            normal);

                        CurveArray curves = creapp.NewCurveArray();

                        foreach (Curve curve in curveLoop2)
                        {
                            curves.Append(curve.CreateTransformed(offset));
                        }

                        // Create model lines for an curve loop.

                        //Plane plane = creapp.NewPlane( curves ); // 2016

                        Plane plane = curveLoop2.GetPlane(); // 2017

                        SketchPlane sketchPlane
                            = SketchPlane.Create(doc, plane);

                        ModelCurveArray curveElements
                            = credoc.NewModelCurveArray(curves,
                                                        sketchPlane);

                        if (isCCW)
                        {
                            foreach (ModelCurve mcurve in curveElements)
                            {
                                OverrideGraphicSettings overrides
                                    = view.GetElementOverrides(
                                          mcurve.Id);

                                overrides.SetProjectionLineColor(
                                    colorRed);

                                view.SetElementOverrides(
                                    mcurve.Id, overrides);
                            }
                        }
                    }
                }
                tx.Commit();
            }
            return(Result.Succeeded);
        }
示例#31
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;
        }
示例#32
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);
        }
示例#33
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;
        }