示例#1
0
        /// <summary>
        /// Sets the color of the Material.
        /// </summary>
        /// <param name="material">Material to set the Color for.</param>
        /// <param name="color">Color to set the Material to.</param>
        /// <returns>Material with the adjusted color.</returns>
        public static Material SetColor(Material material, Color color)
        {
            if (material == null)
            {
                throw new ArgumentNullException(nameof(material));
            }
            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }

            if (!(material.InternalElement is Autodesk.Revit.DB.Material m))
            {
                throw new ArgumentNullException(nameof(material));
            }

            var c   = new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue);
            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            m.Color = c;
            TransactionManager.Instance.TransactionTaskDone();

            return(material);
        }
示例#2
0
        /// <summary>
        /// Sets the Diffuse Color property for the Appearance Asset inside of the Material.
        /// </summary>
        /// <param name="appearanceAsset">Appearance Asset to set the color for.</param>
        /// <param name="color">Color that property will be set to.</param>
        /// <returns>Appearance Asset with the adjusted color property.</returns>
        public static Element SetDiffuseColor(Element appearanceAsset, Color color)
        {
            if (appearanceAsset == null)
            {
                throw new ArgumentNullException(nameof(appearanceAsset));
            }
            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }

            var aa  = appearanceAsset.InternalElement as Autodesk.Revit.DB.AppearanceAssetElement;
            var c   = new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue);
            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            using (var editScope = new Autodesk.Revit.DB.Visual.AppearanceAssetEditScope(doc))
            {
                var editableAsset   = editScope.Start(aa.Id);
                var diffuseProperty = editableAsset.FindByName("generic_diffuse") as Autodesk.Revit.DB.Visual.AssetPropertyDoubleArray4d;
                diffuseProperty.SetValueAsColor(c);
                editScope.Commit(true);
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(aa.ToDSType(true));
        }
示例#3
0
 public void add(Autodesk.Revit.DB.Color c)
 {
     if (c == null)
     {
         add(0);
         add(0);
         add(0);
     }
     else
     {
         add(c.Red);
         add(c.Green);
         add(c.Blue);
     }
 }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object result = new Autodesk.Revit.DB.Color(255, 0, 0);

            if (value != null)
            {
                try
                {
                    System.Windows.Media.Brush wpf = value as System.Windows.Media.Brush;
                    var colorSystem = ((SolidColorBrush)wpf).Color;
                    result = new Autodesk.Revit.DB.Color(colorSystem.R, colorSystem.G, colorSystem.B);
                    return(result);
                }
                catch { }
            }
            return(result);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object result = System.Windows.Media.Brushes.Red;

            if (value != null)
            {
                try
                {
                    ColorRevit           rvt         = value as ColorRevit;
                    System.Drawing.Color colorSystem = System.Drawing.Color.FromArgb(rvt.Red, rvt.Green, rvt.Blue);
                    result = new SolidColorBrush(System.Windows.Media.Color.FromArgb(colorSystem.A, colorSystem.R, colorSystem.G, colorSystem.B));
                    return(result);
                }
                catch { }
            }
            return(result);
        }
示例#6
0
        public ColorChoiceForm(IList <Objects.Change.ChangeTypeEnum> types)
        {
            InitializeComponent();

            treeView1.CheckBoxes = true;
            _root = treeView1.Nodes.Add("Change Type(s)");
            foreach (var typ in types)
            {
                TreeNode tn = _root.Nodes.Add(typ.ToString(), typ.ToString());
                tn.Tag = typ;

                Autodesk.Revit.DB.Color c = Utilities.Settings.GetColor(typ);

                tn.BackColor = Color.FromArgb(c.Red, c.Green, c.Blue);
                tn.Checked   = true;
            }
            _root.ExpandAll();
        }
示例#7
0
 /// <summary>
 /// Convert Revit to DS Color
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 private DSCore.Color ToDSColor(Autodesk.Revit.DB.Color color)
 {
     return(DSCore.Color.ByARGB(255, color.Red, color.Green, color.Blue));
 }
示例#8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 public static string GetColor(Autodesk.Revit.DB.Color color)
 {
     return($"Color(Red = {color.Red}, Green = {color.Green}, Blue = {color.Blue}, Alpha = 255)");
 }
示例#9
0
 public ColorData(string label, Color color) : base(label)
 {
     _color = color;
 }
示例#10
0
 public Color(string label, Autodesk.Revit.DB.Color color) : base(label)
 {
     m_color = color;
 }
示例#11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 public static Color DsColorByColor(Autodesk.Revit.DB.Color color)
 {
     return(!color.IsValid ? null : Color.ByARGB(255, color.Red, color.Green, color.Blue));
 }
示例#12
0
 /// <summary>
 /// Creates a new wrapper for a Revit color
 /// </summary>
 /// <param name="color">A Revit Color</param>
 /// <returns name="color">A wrapped Revit color.</returns>
 public static ColorWrapper Wrap(RevitColor color)
 {
     return(new ColorWrapper(color));
 }
示例#13
0
 internal ColorWrapper(RevitColor _revitColor)
 {
     this.revitColor = _revitColor;
 }