Exemplo n.º 1
0
        private ColorFillSchemeEntry CreateEntry(ColorFillScheme scheme, StorageType type, ElementId fillPatternId, Color color)
        {
            var  entries   = scheme.GetEntries();
            bool isbyRange = scheme.IsByRange;
            ColorFillSchemeEntry lastEntry = null;

            if (entries.Count > 0)
            {
                lastEntry = entries.Last();
            }

            var entry = new ColorFillSchemeEntry(type);

            entry.FillPatternId = fillPatternId;

            switch (type)
            {
            case Autodesk.Revit.DB.StorageType.Double:
                double doubleValue = 0;
                if (lastEntry != null)
                {
                    doubleValue = lastEntry.GetDoubleValue() + 20.00;
                }
                entry.SetDoubleValue(doubleValue);
                break;

            case Autodesk.Revit.DB.StorageType.String:
                string strValue = string.Format("New entry {0}", entries.Count);
                entry.SetStringValue(strValue);
                break;

            case Autodesk.Revit.DB.StorageType.Integer:
                int intValue = 0;
                if (lastEntry != null)
                {
                    intValue = lastEntry.GetIntegerValue() + 20;
                }
                entry.SetIntegerValue(intValue);
                break;

            case Autodesk.Revit.DB.StorageType.ElementId:
                var level = new FilteredElementCollector(document)
                            .OfClass(typeof(Level))
                            .Where(lv => !levelIds.Contains(lv.Id) && lv.Name != "Level 1")
                            .FirstOrDefault();
                levelIds.Add(level.Id);
                entry.SetElementIdValue(level.Id);
                break;

            default:
                throw (new Exception("The type is not correct!"));
            }

            return(entry);
        }
Exemplo n.º 2
0
        private void btnUpdateColor_Click(object sender, EventArgs e)
        {
            try
            {
                ColorFillScheme colorFillScheme = lstSchemes.SelectedItem as ColorFillScheme;
                m_colorFillMgr.ModifyByValueScheme(colorFillScheme);

                lbSchemeResults.Text = String.Format("Entries for {0} have been updated.", colorFillScheme.Name);
            }
            catch (Exception ex)
            {
                lbSchemeResults.Text = ex.Message;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Duplicate a color fill scheme based on an existing one.
        /// </summary>
        /// <param name="scheme">The color fill which that is duplicated.</param>
        /// <param name="schemeName">Name for new color fill scheme.</param>
        /// <param name="schemeTitle">Title for new color fill scheme.</param>
        /// <returns></returns>
        public void DuplicateScheme(ColorFillScheme scheme, string schemeName, string schemeTitle)
        {
            ElementId parameterId = new ElementId(BuiltInParameter.AREA_SCHEME_NAME);

            using (Transaction tr = new Transaction(document))
            {
                tr.Start("CopyScheme");
                ElementId       newSchemeId = scheme.Duplicate(schemeName);
                ColorFillScheme newScheme   = scheme.Document.GetElement(newSchemeId) as ColorFillScheme;
                newScheme.Title      = schemeTitle;
                parameterDefinitions = newScheme.GetSupportedParameterIds().ToList <ElementId>();
                if (parameterDefinitions.Contains(parameterId))
                {
                    newScheme.ParameterDefinition = parameterId;
                }
                tr.Commit();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Make modify to existing color fill scheme
        /// </summary>
        /// <param name="scheme"></param>
        public void ModifyByValueScheme(ColorFillScheme scheme)
        {
            List <ColorFillSchemeEntry> entries    = scheme.GetEntries().ToList();
            List <ColorFillSchemeEntry> newEntries = new List <ColorFillSchemeEntry>();
            StorageType storageType = entries[0].StorageType;
            Random      random      = new Random();
            int         seed        = random.Next(0, 256);

            foreach (var entry in entries)
            {
                seed++;
                ColorFillSchemeEntry newEntry = CreateEntry(scheme, storageType, entry.FillPatternId, GenerateRandomColor(seed));
                switch (storageType)
                {
                case StorageType.Double:
                    newEntry.SetDoubleValue(entry.GetDoubleValue());
                    break;

                case StorageType.Integer:
                    newEntry.SetIntegerValue(entry.GetIntegerValue());
                    break;

                case StorageType.String:
                    newEntry.SetStringValue(entry.GetStringValue());
                    break;

                case StorageType.ElementId:
                    newEntry.SetElementIdValue(entry.GetElementIdValue());
                    break;

                default:
                    break;
                }

                newEntries.Add(newEntry);
            }
            using (Transaction tr = new Transaction(document))
            {
                tr.Start("update entries");
                scheme.SetEntries(newEntries);
                tr.Commit();
            }
            externalCommandData.Application.ActiveUIDocument.RefreshActiveView();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create color legend on view with the specific color fill scheme
        /// </summary>
        /// <param name="scheme"></param>
        /// <param name="view"></param>
        public void CreateAndPlaceLegend(ColorFillScheme scheme, Autodesk.Revit.DB.View view)
        {
            using (Transaction transaction = new Transaction(document))
            {
                transaction.Start("Create legend");
                var origin = view.Origin.Add(view.UpDirection.Multiply(20));

                if (view.CanApplyColorFillScheme(schemeCategoryId, scheme.Id))
                {
                    view.SetColorFillSchemeId(schemeCategoryId, scheme.Id);
                    var legend = ColorFillLegend.Create(document, view.Id, schemeCategoryId, origin);
                    legend.Height = legend.Height / 2;
                    transaction.Commit();
                }
                else
                {
                    throw new Exception("The scheme can not be applied on the view.");
                }
            }
        }
Exemplo n.º 6
0
 private void btnPlaceLegend_Click(object sender, EventArgs e)
 {
     if (lstSchemes.SelectedIndex != -1 && lstViews.SelectedIndex != -1)
     {
         try
         {
             ColorFillScheme        colorFillScheme = lstSchemes.SelectedItem as ColorFillScheme;
             Autodesk.Revit.DB.View view            = lstViews.SelectedItem as Autodesk.Revit.DB.View;
             m_colorFillMgr.CreateAndPlaceLegend(colorFillScheme, view);
             lbLegendResults.Text = string.Format("Color Fill legend is placed on view {0}.", view.Name);
         }
         catch (Exception ex)
         {
             lbLegendResults.Text = ex.Message;
         }
     }
     else
     {
         lbLegendResults.Text = "Please select a scheme and a view to place the legend.";
     }
     lbLegendResults.Refresh();
 }
Exemplo n.º 7
0
 private void btnDuplicate_Click(object sender, EventArgs e)
 {
     if (tbSchemeName.Text != String.Empty && tbSchemeTitle.Text != String.Empty)
     {
         try
         {
             ColorFillScheme colorFillScheme = lstSchemes.SelectedItem as ColorFillScheme;
             m_colorFillMgr.DuplicateScheme(colorFillScheme, tbSchemeName.Text, tbSchemeTitle.Text);
             lbSchemeResults.Text = String.Format("New scheme {0} is created.", tbSchemeName.Text);
             GetData();
         }
         catch (Exception ex)
         {
             lbSchemeResults.Text = ex.Message;
         }
     }
     else
     {
         lbSchemeResults.Text = "Please set the name and title of the new color fill scheme.";
     }
     lbSchemeResults.Refresh();
 }