Example #1
0
        public static void ApplyViewFilter(Document doc, View view, ParameterFilterElement filter, ElementId solidFillPatternId, int colorNumber, bool colorLines, bool colorFill)
        {
            view.AddFilter(filter.Id);
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

            byte red   = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(1, 2), 16);
            byte green = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(3, 2), 16);
            byte blue  = Convert.ToByte(ColorsCollection.colors[colorNumber].Substring(5, 2), 16);

            Color clr = new Color(red, green, blue);

            if (colorLines)
            {
                ogs.SetProjectionLineColor(clr);
                ogs.SetCutLineColor(clr);
            }

            if (colorFill)
            {
#if R2017 || R2018
                ogs.SetProjectionFillColor(clr);
                ogs.SetProjectionFillPatternId(solidFillPatternId);
                ogs.SetCutFillColor(clr);
                ogs.SetCutFillPatternId(solidFillPatternId);
#else
                ogs.SetSurfaceForegroundPatternColor(clr);
                ogs.SetSurfaceForegroundPatternId(solidFillPatternId);
                ogs.SetCutForegroundPatternColor(clr);
                ogs.SetCutForegroundPatternId(solidFillPatternId);
#endif
            }
            view.SetFilterOverrides(filter.Id, ogs);
        }
Example #2
0
        /// <summary>
        ///   Metodo che cambia il colore dei Pannelli nel colore BIANCO
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="uiapp">L'oggetto Applicazione di Revit</param>m>
        ///
        private void ChangeColorToBlank(UIApplication uiapp)
        {
            using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document))
            {
                trans.Start("Change Color");

                foreach (Element ele in _elements)
                {
                    // Metodo per la trasformazione del colore da System.Drawing.Color a Autodesk.Revit.DB.Color
                    System.Drawing.Color colorToConvert = new System.Drawing.Color();
                    colorToConvert = System.Drawing.Color.FromName("White");
                    Autodesk.Revit.DB.Color newColor = new Autodesk.Revit.DB.Color(colorToConvert.R, colorToConvert.G, colorToConvert.B);

                    // Assegna il nuovo colore all'elemento di override delle impostazioni grafiche

                    _ogs.SetSurfaceForegroundPatternColor(newColor);
                    _ogs.SetSurfaceForegroundPatternVisible(true);

                    // Estrae il valore Id per settare il Pattern come Solid FIll(Riempimento)
                    FilteredElementCollector elements         = new FilteredElementCollector(uiapp.ActiveUIDocument.Document);
                    FillPatternElement       solidFillPattern = elements.OfClass(typeof(FillPatternElement))
                                                                .Cast <FillPatternElement>()
                                                                .First(a => a.GetFillPattern().IsSolidFill);
                    ElementId solidFillPatternId = null;

                    if (solidFillPattern.GetFillPattern().IsSolidFill)
                    {
                        solidFillPatternId = solidFillPattern.Id;
                    }

                    // Imposta l'elemento come Solid Fill
                    _ogs.SetSurfaceForegroundPatternId(solidFillPatternId);

                    // Fa l'override delle impostazioni grafiche dell'elemento
                    uiapp.ActiveUIDocument.Document.ActiveView.SetElementOverrides(ele.Id, _ogs);
                    //Autodesk.Revit.DB.Color colorForeground = el.Category.Material.SurfaceForegroundPatternColor;
                    Autodesk.Revit.DB.Color colorForegroundOGS = _ogs.SurfaceForegroundPatternColor;
                }

                trans.Commit();
            }


            //// Refresha la View attiva in modo da attivare il cambiamento
            //uiapp.ActiveUIDocument.RefreshActiveView();
        }
Example #3
0
        /// <summary>
        /// 替换图元显示
        /// </summary>
        public static void SetFilledRegionColor(this View view, ElementId elementId, Color surfaceForegroundPatternColor, Color projectionLineColor, int transparency)
        {
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();//设置投影线、截面线颜色

            ogs.SetSurfaceForegroundPatternColor(surfaceForegroundPatternColor);
            ogs.SetProjectionLineColor(projectionLineColor);
            ogs.SetSurfaceTransparency(transparency);
            view.SetElementOverrides(elementId, ogs);
        }
        // Переопределение графики для фильра IdentityDataAnalysis_Visibility
        private void SetVisibilityFilter(Document doc)
        {
            ElementClassFilter       filter    = new ElementClassFilter(typeof(ParameterFilterElement));
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.WherePasses(filter).ToElements()
            .Cast <ParameterFilterElement>().ToList <ParameterFilterElement>();

            var result =
                from item in collector
                where item.Name.Equals("IdentityDataAnalysis_Visibility")
                select item;

            if (result.Count() > 0)
            {
                ParameterFilterElement filterForVisibility = result.First() as ParameterFilterElement;
                View view = doc.ActiveView;


                using (Transaction t = new Transaction(doc, "SetVisibilityFilter"))
                {
                    t.Start();
                    if (!view.GetFilters().Contains(filterForVisibility.Id))
                    {
                        view.AddFilter(filterForVisibility.Id);
                    }

                    OverrideGraphicSettings settings = new OverrideGraphicSettings();

                    FillPatternElement fillPatternElement = GetSolidFillPaeern(doc);
                    settings.SetSurfaceForegroundPatternId(fillPatternElement.Id);
                    settings.SetSurfaceBackgroundPatternId(fillPatternElement.Id);
                    settings.SetCutForegroundPatternId(fillPatternElement.Id);
                    settings.SetCutBackgroundPatternId(fillPatternElement.Id);

                    Color redColor = new Color(255, 0, 0);
                    settings.SetSurfaceForegroundPatternColor(redColor);
                    settings.SetSurfaceBackgroundPatternColor(redColor);
                    settings.SetCutForegroundPatternColor(redColor);
                    settings.SetCutBackgroundPatternColor(redColor);

                    settings.SetSurfaceTransparency(20);

                    view.SetFilterOverrides(filterForVisibility.Id, settings);
                    t.Commit();
                }
            }
            else
            {
                throw new NullReferenceException();
            }
        }
Example #5
0
        public static void Graphics20192020(Document doc, ref OverrideGraphicSettings overrideGraphicSettings, byte r, byte g, byte b)
        {
#if REVIT2020
            var patternCollector = new FilteredElementCollector(doc);
            patternCollector.OfClass(typeof(FillPatternElement));
            FillPatternElement fpe = patternCollector.ToElements()
                                     .Cast <FillPatternElement>().First(x => x.GetFillPattern().Name == "<Solid fill>");
            overrideGraphicSettings.SetSurfaceForegroundPatternId(fpe.Id);
            overrideGraphicSettings.SetSurfaceForegroundPatternVisible(true);
            overrideGraphicSettings.SetSurfaceForegroundPatternColor(new Autodesk.Revit.DB.Color(r, g, b));
            overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(r, g, b));
#endif
        }
Example #6
0
        public static OverrideGraphicSettings getStandartGraphicSettings(Document doc)
        {
            OverrideGraphicSettings overrideGraphic = new OverrideGraphicSettings();

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

            return(overrideGraphic);
        }
Example #7
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);
        }
        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);
        }
        /// <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);
        }
Example #10
0
        /// <summary>
        /// Animate the color of an element. This will export images of the element, then revert the element back to where it was.
        /// Inspired by the Bad Monkeys team.
        /// </summary>
        /// <param name="element">The element to set color to.</param>
        /// <param name="startColor">The start color.</param>
        /// <param name="endColor">The end color.</param>
        /// <param name="iterations">Numnber of images.</param>
        /// <param name="directoryPath">Where to save the images.</param>
        /// <param name="view">View to export from.</param>
        /// <returns name="element">The element.</returns>
        /// <search>
        ///  rhythm
        /// </search>
        public static object AnimateColor(List <global::Revit.Elements.Element> element, Color startColor, Color endColor, int iterations, string directoryPath, global::Revit.Elements.Element view)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            UIDocument uiDocument          = new UIDocument(doc);

            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)view.InternalElement;
            //create a new form!
            DefaultProgressForm statusBar = new DefaultProgressForm("Exporting Images", "Exporting image {0} of " + iterations.ToString(), "Animate Element Color", iterations + 1);
            //default indices for start and end color
            List <double> defaultIndices = new List <double>();

            defaultIndices.Add(0);
            defaultIndices.Add(1);
            //the color list generated from start and end color
            List <Color> colorList = new List <Color>();

            colorList.Add(startColor);
            colorList.Add(endColor);
            //where to start
            double startValue = 0;

            //starts a transaction group so we can roolback the changes after
            using (TransactionGroup transactionGroup = new TransactionGroup(doc, "group"))
            {
                TransactionManager.Instance.ForceCloseTransaction();
                transactionGroup.Start();
                using (Transaction t2 = new Transaction(doc, "Animate Color"))
                {
                    int num2 = 0;
                    while (startValue <= 1)
                    {
                        statusBar.Activate();
                        t2.Start();
                        //declare the graphic settings overrides
                        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                        //generate color range
                        Color dscolor = DSCore.Color.BuildColorFrom1DRange(colorList, defaultIndices, startValue);
                        //convert to revit color
                        Autodesk.Revit.DB.Color revitColor = new Autodesk.Revit.DB.Color(dscolor.Red, dscolor.Green,
                                                                                         dscolor.Blue);
                        //solid fill id
                        FilteredElementCollector  fillPatternCollector = new FilteredElementCollector(doc);
                        Autodesk.Revit.DB.Element solidFill            = fillPatternCollector.OfClass(typeof(FillPatternElement)).ToElements().FirstOrDefault(x => x.Name.ToLower() == "solid fill");

                        ElementId pattId = new ElementId(20);
                        //set the overrides to the graphic settings
                        ogs.SetSurfaceForegroundPatternColor(revitColor);
                        ogs.SetSurfaceForegroundPatternId(solidFill.Id);
                        foreach (var e in element)
                        {
                            //apply the changes to view
                            internalView.SetElementOverrides(e.InternalElement.Id, ogs);
                        }
                        t2.Commit();

                        uiDocument.RefreshActiveView();
                        var exportOpts = new ImageExportOptions
                        {
                            FilePath              = directoryPath + num2.ToString(),
                            FitDirection          = FitDirectionType.Horizontal,
                            HLRandWFViewsFileType = ImageFileType.PNG,
                            ImageResolution       = ImageResolution.DPI_300,
                            ShouldCreateWebSite   = false
                        };
                        doc.ExportImage(exportOpts);
                        ++num2;
                        startValue = startValue + (1.0 / iterations);
                        statusBar.Increment();
                    }
                }
                transactionGroup.RollBack();
            }
            statusBar.Close();

            return(element);
        }
Example #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication val  = commandData.get_Application();
            Document      val2 = val.get_ActiveUIDocument().get_Document();
            Selection     val3 = val.get_ActiveUIDocument().get_Selection();

            try
            {
                if (lodFilterForm == null)
                {
                    lodFilterForm = new LODfilterForm();
                }
                lodFilterForm.ShowDialog();
                if (lodFilterForm.DialogResult != DialogResult.OK)
                {
                    return(1);
                }
                bool[] fillColorEnabled   = lodFilterForm.GetFillColorEnabled();
                bool[] lineColorEnabled   = lodFilterForm.GetLineColorEnabled();
                bool[] visibilitesEnabled = lodFilterForm.GetVisibilitesEnabled();
                int[]  transparencies     = lodFilterForm.GetTransparencies();
                CreateFiltersIfMissing(val2);
                IList <ElementId> list = ApplyLODfiltersToView(val2, val2.get_ActiveView());
                Transaction       val4 = new Transaction(val2, "Apply LOD filters");
                val4.Start();
                View val5 = val2.get_ActiveView();
                for (int i = 0; i < filterNames.Length; i++)
                {
                    OverrideGraphicSettings val6 = new OverrideGraphicSettings();
                    if (lineColorEnabled[i])
                    {
                        val6.SetCutLineColor(lodFilterColors[i]);
                        val6.SetProjectionLineColor(lodFilterColors[i]);
                    }
                    ElementId solidFillId = GetSolidFillId(val2);
                    if (fillColorEnabled[i])
                    {
                        val6.SetCutForegroundPatternColor(lodFilterColors[i]);
                        val6.SetCutBackgroundPatternColor(lodFilterColors[i]);
                        val6.SetSurfaceForegroundPatternColor(lodFilterColors[i]);
                        val6.SetSurfaceBackgroundPatternColor(lodFilterColors[i]);
                        val6.SetSurfaceForegroundPatternId(solidFillId);
                        val6.SetSurfaceBackgroundPatternId(solidFillId);
                    }
                    val6.SetSurfaceTransparency(transparencies[i]);
                    val5.SetFilterOverrides(list[i], val6);
                    val5.SetFilterVisibility(list[i], visibilitesEnabled[i]);
                }
                val4.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
        public void Execute(UIApplication uiapp)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                if (myWindow1.myWindow4.myListViewEE.Items.Count == 0)
                {
                    MessageBox.Show("Please save an an arrangement");
                    return;
                }

                if (myWindow1.myWindow4.myListViewEE.SelectedIndex == -1)
                {
                    myWindow1.myWindow4.myListViewEE.SelectedIndex = 0;
                }

                Random rnd = new Random();

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Randomise Colour");

                    KeyValuePair <string, Autodesk.Revit.DB.ExtensibleStorage.Entity> myKeyValuePair = (KeyValuePair <string, Entity>)myWindow1.myWindow4.myListViewEE.SelectedItem;

                    IDictionary <ElementId, XYZ> dict_Child = myKeyValuePair.Value.Get <IDictionary <ElementId, XYZ> >("FurnLocations", DisplayUnitType.DUT_MILLIMETERS);

                    string myStringAggregate_Location = "";

                    foreach (KeyValuePair <ElementId, XYZ> myKP in dict_Child)
                    {
                        Element Searchelem = doc.GetElement(myKP.Key);
                        if (Searchelem == null)
                        {
                            continue;
                        }

                        if (Searchelem.Category.Name != "Furniture")
                        {
                            continue;
                        }


                        OverrideGraphicSettings ogs       = new OverrideGraphicSettings();
                        OverrideGraphicSettings ogsCheeck = doc.ActiveView.GetElementOverrides(myKP.Key);
                        //FillPatternElement myFillPattern = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast<FillPatternElement>().First(a => a.Name.Contains("Solid fill"));
                        List <FillPatternElement> myListFillPattern = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast <FillPatternElement>().Where(x => x.GetFillPattern().Target == FillPatternTarget.Drafting).ToList();

                        FillPatternElement myFillPattern = myListFillPattern[(byte)rnd.Next(0, myListFillPattern.Count - 1)];



                        Color myColor_Random01          = new Autodesk.Revit.DB.Color((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256));
                        Color myColor_Random01_Brighter = ChangeColorBrightness(myColor_Random01, (float)0.5);


                        ogs.SetSurfaceForegroundPatternId(myFillPattern.Id);
                        ogs.SetSurfaceForegroundPatternColor(myColor_Random01);
                        ogs.SetProjectionLineWeight(5);
                        ogs.SetProjectionLineColor(myColor_Random01);


                        FillPatternElement myFillPattern_SolidFill = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast <FillPatternElement>().First(a => a.Name.Contains("Solid fill"));
                        ogs.SetSurfaceBackgroundPatternId(myFillPattern_SolidFill.Id);
                        ogs.SetSurfaceBackgroundPatternColor(myColor_Random01_Brighter);

                        doc.ActiveView.SetElementOverrides(myKP.Key, ogs);

                        myStringAggregate_Location = myStringAggregate_Location + Environment.NewLine + ((FamilyInstance)doc.GetElement(myKP.Key)).get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString() + "," + Math.Round(myKP.Value.X, 2) + "," + Math.Round(myKP.Value.Y, 2) + "," + Math.Round(myKP.Value.Z, 2);
                    }
                    tx.Commit();
                }


                myWindow1.myEE13_ExtensibleStorage_NewOrSave.myBool_New = false;
                myWindow1.myExternalEvent_EE13_ExtensibleStorage_NewOrSave.Raise();
            }

            #region catch and finally
            catch (Exception ex)
            {
                _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE13_ExtensibleStorage_zRandomise" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
            }
            finally
            {
            }
            #endregion
        }
Example #13
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

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

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

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

            ElementMulticategoryFilter filter1 = new ElementMulticategoryFilter(builtInCats);

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

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

            Random pRand = new Random();


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

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

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

                t.Commit();
            }



            return(Result.Succeeded);
        }
Example #14
0
        private static void CreateHeatMap(UIApplication app, CarboProject carboLifeProject)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            using (Transaction t = new Transaction(doc, "Create Heatmap"))
            {
                t.Start();



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

                List <CarboElement> elementsFromGroups = carboLifeProject.getElementsFromGroups().ToList();

                foreach (CarboElement ce in elementsFromGroups)
                {
                    ElementId id    = new ElementId(ce.Id);
                    ElementId patid = solidFillPattern.Id; //Solid

                    OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                    ogs.SetHalftone(false);

                    ogs.SetProjectionLineColor(new Color(ce.r, ce.g, ce.b));
                    ogs.SetSurfaceTransparency(0);

                    ogs.SetProjectionLineWeight(1);

                    //Solid Fill;
                    Color elementColour = new Color(ce.r, ce.g, ce.b);

                    ogs.SetProjectionLineWeight(1);
                    ogs.SetSurfaceForegroundPatternId(patid);
                    ogs.SetSurfaceForegroundPatternColor(elementColour);
                    ogs.SetSurfaceForegroundPatternVisible(true);

                    ogs.SetCutLineWeight(1);
                    ogs.SetCutForegroundPatternId(patid);
                    ogs.SetCutForegroundPatternVisible(true);
                    ogs.SetCutForegroundPatternColor(elementColour);

                    //Set the override
                    try
                    {
                        Element elementcheck = doc.GetElement(id);
                        if (elementcheck != null)
                        {
                            doc.ActiveView.SetElementOverrides(id, ogs);

                            Parameter carboPar = elementcheck.LookupParameter("EmbodiedCarbon");
                            if (carboPar != null)
                            {
                                carboPar.Set(ce.EC_Total);
                            }
                            else
                            {
                                CreateParameter(app, elementcheck);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                t.Commit();
            }
        }
Example #15
0
        public void Execute(UIApplication uiapp)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name);


                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Show Arrangement");

                    KeyValuePair <string, Entity> myKeyValuePair = (KeyValuePair <string, Entity>)myWindow1.myWindow4.myListViewEE.SelectedItem;

                    IDictionary <ElementId, XYZ> dict_Child = myKeyValuePair.Value.Get <IDictionary <ElementId, XYZ> >("FurnLocations", DisplayUnitType.DUT_MILLIMETERS);

                    string myStringAggregate_Location = "";

                    foreach (KeyValuePair <ElementId, XYZ> myKP in dict_Child)
                    {
                        Element Searchelem = doc.GetElement(myKP.Key);
                        if (Searchelem == null)
                        {
                            continue;
                        }

                        ElementTransformUtils.MoveElement(doc, myKP.Key, myKP.Value - ((LocationPoint)Searchelem.Location).Point);

                        myStringAggregate_Location = myStringAggregate_Location + Environment.NewLine + ((FamilyInstance)doc.GetElement(myKP.Key)).get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString() + "," + Math.Round(myKP.Value.X, 2) + "," + Math.Round(myKP.Value.Y, 2) + "," + Math.Round(myKP.Value.Z, 2);
                    }


                    IDictionary <ElementId, double> dict_Child_Angle = myKeyValuePair.Value.Get <IDictionary <ElementId, double> >("FurnLocations_Angle", DisplayUnitType.DUT_MILLIMETERS);

                    string myStringAggregate_Angle = "";

                    foreach (KeyValuePair <ElementId, double> myKP in dict_Child_Angle)
                    {
                        FamilyInstance Searchelem = doc.GetElement(myKP.Key) as FamilyInstance;
                        if (Searchelem == null)
                        {
                            continue;
                        }

                        Line line = Line.CreateBound(((LocationPoint)Searchelem.Location).Point, ((LocationPoint)Searchelem.Location).Point + XYZ.BasisZ);

                        double myDouble = Searchelem.GetTransform().BasisX.AngleOnPlaneTo(XYZ.BasisY, XYZ.BasisZ) - myKP.Value;

                        ElementTransformUtils.RotateElement(doc, myKP.Key, line, myDouble);

                        myStringAggregate_Angle = myStringAggregate_Angle + Environment.NewLine + (IsZero(myKP.Value, _eps) ? 0 : Math.Round(myKP.Value, 2));
                    }



                    IDictionary <ElementId, ElementId> dict_Child_Pattern = myKeyValuePair.Value.Get <IDictionary <ElementId, ElementId> >("FurnLocations_Pattern", DisplayUnitType.DUT_MILLIMETERS);
                    IDictionary <ElementId, int>       dict_Child_Red     = myKeyValuePair.Value.Get <IDictionary <ElementId, int> >("FurnLocations_ColorRed", DisplayUnitType.DUT_MILLIMETERS);
                    IDictionary <ElementId, int>       dict_Child_Green   = myKeyValuePair.Value.Get <IDictionary <ElementId, int> >("FurnLocations_ColorGreen", DisplayUnitType.DUT_MILLIMETERS);
                    IDictionary <ElementId, int>       dict_Child_Blue    = myKeyValuePair.Value.Get <IDictionary <ElementId, int> >("FurnLocations_ColorBlue", DisplayUnitType.DUT_MILLIMETERS);



                    int myInt = -1;
                    foreach (KeyValuePair <ElementId, ElementId> myKP in dict_Child_Pattern)
                    {
                        myInt++;
                        FamilyInstance Searchelem = doc.GetElement(myKP.Key) as FamilyInstance;
                        if (Searchelem == null)
                        {
                            continue;
                        }
                        if (Searchelem.Category.Name != "Furniture")
                        {
                            continue;
                        }

                        OverrideGraphicSettings ogs       = new OverrideGraphicSettings();
                        OverrideGraphicSettings ogsCheeck = doc.ActiveView.GetElementOverrides(myKP.Key);

                        Color myColor         = new Autodesk.Revit.DB.Color((byte)dict_Child_Red[myKP.Key], (byte)dict_Child_Green[myKP.Key], (byte)dict_Child_Blue[myKP.Key]);
                        Color myColorBrighter = ChangeColorBrightness(myColor, (float)0.5);


                        ogs.SetSurfaceForegroundPatternId(myKP.Value);
                        ogs.SetSurfaceForegroundPatternColor(myColor);
                        ogs.SetProjectionLineWeight(5);
                        ogs.SetProjectionLineColor(myColor);


                        FillPatternElement myFillPattern_SolidFill = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast <FillPatternElement>().First(a => a.Name.Contains("Solid fill"));
                        ogs.SetSurfaceBackgroundPatternId(myFillPattern_SolidFill.Id);
                        ogs.SetSurfaceBackgroundPatternColor(myColorBrighter);


                        doc.ActiveView.SetElementOverrides(myKP.Key, ogs);
                    }


                    tx.Commit();
                }
            }

            #region catch and finally
            catch (Exception ex)
            {
                _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE13_ExtensibleStorage_Rearrange" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
            }
            finally
            {
            }
            #endregion
        }