<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to change text color ? in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7799514#M82548</link>
    <description>&lt;P&gt;Dear Rudi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would this be equivalent (and faster) using the bitwise shift operator?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    /// &amp;lt;summary&amp;gt;
    /// Revit text colour parameter value stored as an integer 
    /// in text note type BuiltInParameter.LINE_COLOR.
    /// &amp;lt;/summary&amp;gt;
    private int GetRevitTextColorFromSystemColor( 
      System.Drawing.Color color )
    {
      //return (int) color.R
      //  + (int) color.G * (int) Math.Pow( 2, 8 )
      //  + (int) color.B * (int) Math.Pow( 2, 16 );

      return (int) color.R 
        + (int) color.G &amp;lt;&amp;lt; 8
        + (int) color.B &amp;lt;&amp;lt; 16;
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Probably not... cf.&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/1933597/when-to-use-shift-operators-in-c" target="_blank"&gt;https://stackoverflow.com/questions/1933597/when-to-use-shift-operators-in-c&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Feb 2018 13:44:00 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2018-02-22T13:44:00Z</dc:date>
    <item>
      <title>How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/2567672#M82544</link>
      <description>Hi everyone,&lt;BR /&gt;
&lt;BR /&gt;
I am using the ColorDialog control from VisualStudio 2008 in  order to &lt;BR /&gt;
select a color and then I retrieve the RGB components in three variables:&lt;BR /&gt;
&lt;BR /&gt;
ColorComponentRed&lt;BR /&gt;
ColorComponentGreen&lt;BR /&gt;
ColorComponentBlue&lt;BR /&gt;
&lt;BR /&gt;
What I want is to assign this color to some text (it is text because it's &lt;BR /&gt;
filtered as this) but the following code is not working:&lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
Dim colorparam As Parameter&lt;BR /&gt;
colorparam = &lt;BR /&gt;
elem.ObjectType.Parameter(parameterId:=Parameters.BuiltInParameter.TEXT_COLOR)&lt;BR /&gt;
&lt;BR /&gt;
Dim app As New Autodesk.Revit.Creation.Application()&lt;BR /&gt;
Dim color As Autodesk.Revit.Color = app.NewColor()&lt;BR /&gt;
&lt;BR /&gt;
color.Red = ColorComponentRed&lt;BR /&gt;
color.Green = ColorComponentGreen&lt;BR /&gt;
color.Blue = ColorComponentBlue&lt;BR /&gt;
&lt;BR /&gt;
colorparam.Set(color)&lt;BR /&gt;
[/code]&lt;BR /&gt;
&lt;BR /&gt;
Can anybody tell me what I am doing wrong and how to do it, please ?&lt;BR /&gt;
&lt;BR /&gt;
TIA&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
Humans are born with a wide horizon.&lt;BR /&gt;
As time goes by, the horizon narrows and&lt;BR /&gt;
narrows, until it becomes a point of view.</description>
      <pubDate>Mon, 05 Oct 2009 22:09:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/2567672#M82544</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-10-05T22:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794306#M82545</link>
      <description>&lt;P&gt;I have the same problem. Did you find a solution?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 09:17:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794306#M82545</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-21T09:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794436#M82546</link>
      <description>&lt;P&gt;Do you want to change the color of an annotation in Revit? If so, have you tried opening a transaction to do that? You can only change anything in the model if it is inside a transaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-BECA30DB-23B4-4E71-BE24-DC4DD176E52D-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-BECA30DB-23B4-4E71-BE24-DC4DD176E52D-htm.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 10:01:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794436#M82546</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-21T10:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794507#M82547</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;private int GetRevitTextColorFromSystemColor(System.Drawing.Color color)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return (int)color.R * (int)Math.Pow(2, 0) + (int)color.G * (int)Math.Pow(2, 8) + (int)color.B * (int)Math.Pow(2, 16);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...I know that 2^0 is just 1, so you could better use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;private int GetRevitTextColorFromSystemColor(System.Drawing.Color color)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return (int)color.R + (int)color.G * (int)Math.Pow(2, 8) + (int)color.B * (int)Math.Pow(2, 16);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;int color= GetRevitTextColorFromSystemColor(yourSystemColor);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;textNoteType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(color);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that starting with Revit 2017, there is a ColorSelectionDialog available.&lt;/P&gt;
&lt;P&gt;You can use its SelectedColor property to get a Revit color instead of a system color.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Revitalizer&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 10:29:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7794507#M82547</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2018-02-21T10:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7799514#M82548</link>
      <description>&lt;P&gt;Dear Rudi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would this be equivalent (and faster) using the bitwise shift operator?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    /// &amp;lt;summary&amp;gt;
    /// Revit text colour parameter value stored as an integer 
    /// in text note type BuiltInParameter.LINE_COLOR.
    /// &amp;lt;/summary&amp;gt;
    private int GetRevitTextColorFromSystemColor( 
      System.Drawing.Color color )
    {
      //return (int) color.R
      //  + (int) color.G * (int) Math.Pow( 2, 8 )
      //  + (int) color.B * (int) Math.Pow( 2, 16 );

      return (int) color.R 
        + (int) color.G &amp;lt;&amp;lt; 8
        + (int) color.B &amp;lt;&amp;lt; 16;
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Probably not... cf.&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/1933597/when-to-use-shift-operators-in-c" target="_blank"&gt;https://stackoverflow.com/questions/1933597/when-to-use-shift-operators-in-c&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 13:44:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7799514#M82548</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-22T13:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7799612#M82549</link>
      <description>&lt;P&gt;Hi Jeremy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't use the bitwise operators so far,&lt;/P&gt;
&lt;P&gt;but if providing the same result, it is the more elegant way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One could replace the System.Drawing.Color by Autodesk.Revit.DB.Color,&lt;/P&gt;
&lt;P&gt;the R, G, B properties by their Red, Green, Blue equivalent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rudi&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 14:02:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7799612#M82549</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2018-02-22T14:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806255#M82550</link>
      <description>&lt;P&gt;Dear Rudi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried it out, but it seems to have no effect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewTextNote.cs#L196-L211" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewTextNote.cs#L196-L211&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;      using( Transaction t = new Transaction( doc ) )
      {
        t.Start( "Change Text Colour" );

        int color = Util.ToColorParameterValue( 
          255, 0, 0 );

        Element textNoteType = doc.GetElement( 
          txNote.GetTypeId() );

        textNoteType.get_Parameter( 
          BuiltInParameter.LINE_COLOR )
            .Set( color );

        t.Commit();
      }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 21:33:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806255#M82550</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-24T21:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806351#M82551</link>
      <description>&lt;P&gt;the return value for the &lt;SPAN style="color: rgb(25, 25, 112);"&gt;GetRevitTextColorFromSystemColor() method needs to be&lt;/SPAN&gt;&lt;SPAN style="color: rgb(25, 25, 112); font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="color: rgb(25, 25, 112); font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="color: rgb(0, 0, 128);"&gt;return&lt;/SPAN&gt;&amp;nbsp;(&lt;SPAN style="color: rgb(255, 0, 0); font-weight: bold;"&gt;int&lt;/SPAN&gt;)(&amp;nbsp;color.R&amp;nbsp;+&amp;nbsp;(color.G&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&lt;SPAN style="color: rgb(0, 0, 139);"&gt;8&lt;/SPAN&gt;)&amp;nbsp;&amp;nbsp;+&amp;nbsp;(color.B&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&lt;SPAN style="color: rgb(0, 0, 139);"&gt;16&lt;/SPAN&gt;));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 23:13:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806351#M82551</guid>
      <dc:creator>FAIR59</dc:creator>
      <dc:date>2018-02-24T23:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806411#M82552</link>
      <description>&lt;P&gt;Quite convenient as extension methods:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &amp;lt;Extension()&amp;gt; _
    Public Function AsRGB(ByVal Parameter As Parameter) As Byte()
        Dim I As Integer = Parameter.AsInteger
        Dim Red As Byte = I Mod 256
        I = I \ 256
        Dim Green As Byte = I Mod 256
        I = I \ 256
        Dim Blue As Byte = I Mod 256
        Return New Byte(2) {Red, Green, Blue}
    End Function
    &amp;lt;Extension()&amp;gt; _
    Public Function AsParameterValue(ByVal Color As Color) As Integer
        Return Color.Red + (256 * Color.Green) + (65536 * Color.Blue)
    End Function
    &amp;lt;Extension()&amp;gt; _
    Public Function AsParameterValue(ByVal Color As Windows.Media.Color) As Integer
        Return Color.R + (256 * Color.G) + (65536 * Color.B)
    End Function
    &amp;lt;Extension()&amp;gt; _
    Public Function AsParameterValue(ByVal Color As System.Drawing.Color) As Integer
        Return Color.R + (256 * Color.G) + (65536 * Color.B)
    End Function&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Feb 2018 01:19:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7806411#M82552</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2018-02-25T01:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to change text color ?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7812764#M82553</link>
      <description>&lt;P&gt;Thank you for the suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem was the .NET shift operator precedence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus '+' tkaes higher precedence than left shift '&amp;lt;&amp;lt;', so I had to add parentheses like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    /// &amp;lt;summary&amp;gt;
    /// Revit text colour parameter value stored as an integer 
    /// in text note type BuiltInParameter.LINE_COLOR.
    /// &amp;lt;/summary&amp;gt;
    public static int ToColorParameterValue( 
      int red, 
      int green, 
      int blue )
    {
      return red + (green &amp;lt;&amp;lt; 8) + (blue &amp;lt;&amp;lt; 16);
    }&lt;/PRE&gt;
&lt;P&gt;Final result tested and working in The Building Coder samples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L455-L488" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L455-L488&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewTextNote.cs#L196-L216" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewTextNote.cs#L196-L216&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 15:18:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7812764#M82553</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-27T15:18:31Z</dc:date>
    </item>
  </channel>
</rss>

