Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
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.
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
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!
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
I hope this helps.
Thank yo for the helpful information. With the provided formula, I can create the Int value for the color and compare them.
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.