Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set Dimension type Color

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
longt61
1023 Views, 4 Replies

Set Dimension type Color

I am using Revit Api 2019.2 and have encountered this strange problem.

I tried to duplicate a dimension type and assign a red color to it as follow:

 

// I tried to set red color to dimension type
System.Drawing.Color sysColor = System.Drawing.Color .FromArgb(255, 0,0);
int intValue = sysColor.ToArgb();

dimType = originalDimType.Duplicate(typeName) as DimensionType;
Parameter param = dimType.get_Parameter(BuiltInParameter.LINE_COLOR);
param.Set(intValue); // the value is 16711680, which is blue

And I get a new dimension type with blue color.

However if I hardcode the int value as 255, I get a red color

param.Set(255); // red color

I don't understand what happened here and why there is a difference between System.Drawing.Color and Autodesk.Revit.DB.Color converting RGB value to int value?

How does this conversion process happen? Is there an other way to set line color for dimension type using Color / RGB value directly? Thank you all very much.

4 REPLIES 4
Message 2 of 5
jeremytammik
in reply to: longt61

I would suggest setting various different colours manually in the user interface and using RevitLookup to analyse what results that has and how the different colours are represented in the database. Then all will become clear. Please let us know what you find out. Thank you!

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5
naveen.kumar.t
in reply to: longt61

Hi @longt61 ,

try using this below code

DimensionType originalType;
                DimensionType duplicateType = originalType.Duplicate("duplicated dimension type name") as DimensionType;
                Parameter colorParam = duplicateType.get_Parameter(BuiltInParameter.LINE_COLOR);
                if(colorParam!=null)
                {
                    System.Drawing.Color sysColor = System.Drawing.Color.FromArgb(255, 0,0 );
                    int intColor = GetLineColorFromSystemColor(sysColor);
                    colorParam.Set(intColor);
                }

Method

private int GetLineColorFromSystemColor(System.Drawing.Color color)
        {
             return (int)color.R + (int)color.G * (int)Math.Pow(2, 😎 + (int)color.B * (int)Math.Pow(2, 16);
        } 

 

I used the method(GetLineColorFromSystemColor()) mentioned in this below link 

https://thebuildingcoder.typepad.com/blog/2018/02/changing-text-colour.html?utm_source=feedburner&ut... 

 

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 4 of 5
longt61
in reply to: naveen.kumar.t

Thank yo for the helpful information. With the provided formula, I can create the Int value for the color and compare them. 

Message 5 of 5
longt61
in reply to: jeremytammik

Sorry for the late respond, I already try changing the dimension type color through Revit interface and get the same result. Since I don't know the formula to calculate the Revit color int value, I have to use the System.Drawing.Color methods FromArgb() and ToArgb() in hope that it will have the same formula as Revit color.  

Thanks to @naveen.kumar.t has point me to the correct direction and the help from one of your post, I can achieve what I want. However, that also proven that the int value for System.Drawing.Color and Autodesk.Revit.DB.Color are calculate differently. I can take a fuzzy guess that the parameter (R, G, B) are taken in reversed order so that the int value for Red and Blue are inter-changed (this is what I received when I set the alpha/opaque to 0).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report