<?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 can replace text in Textnote by keeping same formatting in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10014918#M28956</link>
    <description>&lt;P&gt;Hi FAIR59,&lt;/P&gt;&lt;P&gt;Thank you very much its working fine..&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 04:20:35 GMT</pubDate>
    <dc:creator>kite15</dc:creator>
    <dc:date>2021-01-20T04:20:35Z</dc:date>
    <item>
      <title>How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012785#M28951</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to replace the text with another text by keeping same formatting (Revit 2020).&lt;/P&gt;&lt;P&gt;Actually, there have a same discussion:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/revit-api-forum/replace-text-in-text-note-and-keep-formatting/m-p/3479758#M2732" target="_blank"&gt;https://forums.autodesk.com/t5/revit-api-forum/replace-text-in-text-note-and-keep-formatting/m-p/3479758#M2732&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have tried as per above discussion, However, after replace the text its became all as under line text formatting...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ReplaceTextNoteWithSameFormat.png" style="width: 702px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/868438iA5B874FD0C719EA1/image-dimensions/702x151?v=v2" width="702" height="151" role="button" title="ReplaceTextNoteWithSameFormat.png" alt="ReplaceTextNoteWithSameFormat.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;TextNote textNote = revitDocument.GetElement(elementId) as TextNote;
                            FormattedText formattedText = textNote.GetFormattedText();
                            TextRange range = formattedText.AsTextRange();
                            string plainText = textNote.Text;
                            if (!string.IsNullOrEmpty(updatedText))
                            {
                                plainText = plainText.Replace(searchedText, updatedText);
                                formattedText.SetPlainText(range, plainText);
                            }
                            textNote.SetFormattedText(formattedText);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 14:11:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012785#M28951</guid>
      <dc:creator>kite15</dc:creator>
      <dc:date>2021-01-19T14:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012842#M28952</link>
      <description>&lt;P&gt;i don't see anything in that code that would make it underline. it may be coming from the text type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if its a text note in Revit, depending on where the underlining is set, you have 2 options. Option 1 is global, option 2 is by instance.&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;select the Text Type, Edit Type, and uncheck the Underline option.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;double click on the text, select all and unselect the Underline option in the ribbon.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 19 Jan 2021 14:28:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012842#M28952</guid>
      <dc:creator>hmunsell</dc:creator>
      <dc:date>2021-01-19T14:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012950#M28953</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;1. It's happening due to first word is formatted with underline.&lt;/P&gt;&lt;P&gt;2. I am looking for automation not considering the manual approach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ReplaceTextNoteWithSameFormat1.png" style="width: 544px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/868473iF470F73F4F98C132/image-dimensions/544x117?v=v2" width="544" height="117" role="button" title="ReplaceTextNoteWithSameFormat1.png" alt="ReplaceTextNoteWithSameFormat1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;please, suggest regarding the text formatting automation procedure for TextNote element in Revit API2020, in that case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 15:01:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10012950#M28953</guid>
      <dc:creator>kite15</dc:creator>
      <dc:date>2021-01-19T15:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10013017#M28954</link>
      <description>&lt;P&gt;so you know what is causing the problem then. It is the first word, which is probably edited by double clicking on the text and only selecting that word to underline &lt;EM&gt;(vs being a type setting)&lt;/EM&gt;. The code is just selecting the style of the first word and applying it to the whole text string. not sure your gonna be able to easily get around that in the code.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;is the &lt;STRONG&gt;REF&lt;/STRONG&gt; (highlighted in green) the only thing changing?&lt;/LI&gt;
&lt;LI&gt;is it the same in all instances or does it change?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Could you use the native&amp;nbsp;&lt;A href="https://help.autodesk.com/view/RVT/2019/ENU/?guid=GUID-15FD9B90-D3A5-496E-930B-E86D0680BD27" target="_blank" rel="noopener"&gt;Find and Replace&lt;/A&gt; tool in Revit?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 15:24:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10013017#M28954</guid>
      <dc:creator>hmunsell</dc:creator>
      <dc:date>2021-01-19T15:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10013850#M28955</link>
      <description>&lt;P&gt;a FormattedText can have multiple ranges, first you'd have to find the range&amp;nbsp; of the searchText, and then you can update only that range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;TextRange range = formattedText.Find(searchedText,0,false,false);
string plainText = textNote.Text.Substring(range.Start,range.Length);
if (!string.IsNullOrEmpty(updatedText))
{
    plainText = plainText.Replace(searchedText, updatedText);
    formattedText.SetPlainText(range, plainText);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 19:16:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10013850#M28955</guid>
      <dc:creator>FAIR59</dc:creator>
      <dc:date>2021-01-19T19:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10014918#M28956</link>
      <description>&lt;P&gt;Hi FAIR59,&lt;/P&gt;&lt;P&gt;Thank you very much its working fine..&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 04:20:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10014918#M28956</guid>
      <dc:creator>kite15</dc:creator>
      <dc:date>2021-01-20T04:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can replace text in Textnote by keeping same formatting</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10122501#M28957</link>
      <description>&lt;P&gt;Not sure if this issue has been resolved, but here is a lengthy method for maintaining formatting when text is replaced:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;void ReplaceTextInTextNote(TextNote txnote,
int index, //index of first character in text to be replaced
int range, //number of characters to be replaced
string addText) //text to replace the removed characters
            {
                FormattedText ftx = txnote.GetFormattedText();
                string newText = txnote.Text;

                //Collect Current UnderlineStatuses, BoldStatuses, italicstatuses, superscriptStatuses, per char in txno.Text
                                
                List&amp;lt;bool&amp;gt; underlineStatuses = new List&amp;lt;bool&amp;gt;();
                List&amp;lt;bool&amp;gt; boldStatuses = new List&amp;lt;bool&amp;gt;();
                List&amp;lt;bool&amp;gt; italicStatuses = new List&amp;lt;bool&amp;gt;();
                List&amp;lt;bool&amp;gt; superscriptStatuses = new List&amp;lt;bool&amp;gt;();
                List&amp;lt;bool&amp;gt; subscriptStatuses = new List&amp;lt;bool&amp;gt;();
                for (int i = 0; i &amp;lt; txno.Text.Length; i++)
                {
                    if (ftx.GetUnderlineStatus(new TextRange(i, 1)).ToString() == "All") { underlineStatuses.Add(true); }
                    else { underlineStatuses.Add(false);  }

                    if (ftx.GetBoldStatus(new TextRange(i, 1)).ToString() == "All") { boldStatuses.Add(true); }
                    else { boldStatuses.Add(false); }

                    if (ftx.GetItalicStatus(new TextRange(i, 1)).ToString() == "All") { italicStatuses.Add(true); }
                    else { italicStatuses.Add(false); }

                    if (ftx.GetSuperscriptStatus(new TextRange(i, 1)).ToString() == "All") { superscriptStatuses.Add(true); }
                    else { superscriptStatuses.Add(false); }

                    if (ftx.GetSubscriptStatus(new TextRange(i, 1)).ToString() == "All") { subscriptStatuses.Add(true); }
                    else { subscriptStatuses.Add(false); }
                }
                
                //Remove Replaced Text
                underlineStatuses.RemoveRange(index, range);
                boldStatuses.RemoveRange(index, range);
                italicStatuses.RemoveRange(index, range);
                superscriptStatuses.RemoveRange(index, range);
                subscriptStatuses.RemoveRange(index, range);

                newText = newText.Remove(index, range);
             
                //Add new Text
                newText = newText.Insert(index, addText);

                //Shall the inserted Text be underlined, bold
                bool underlineAddText = ftx.GetUnderlineStatus(new TextRange(index, 1)).ToString() == "All";
                bool boldAddText = ftx.GetBoldStatus(new TextRange(index, 1)).ToString() == "All";
                bool italicAddText = ftx.GetItalicStatus(new TextRange(index, 1)).ToString() == "All";                
                bool superscriptAddText = ftx.GetSuperscriptStatus(new TextRange(index, 1)).ToString() == "All";
                bool subscriptAddText = ftx.GetSubscriptStatus(new TextRange(index, 1)).ToString() == "All";

                //Add the same formatting to a list to be added to underline,bold, italic, subscript, superscript statuses
                underlineStatuses.InsertRange(index, (Enumerable.Repeat(underlineAddText, addText.Length)));
                boldStatuses.InsertRange(index, (Enumerable.Repeat(boldAddText, addText.Length)));
                italicStatuses.InsertRange(index, (Enumerable.Repeat(italicAddText, addText.Length)));
                superscriptStatuses.InsertRange(index, (Enumerable.Repeat(superscriptAddText, addText.Length)));
                subscriptStatuses.InsertRange(index, (Enumerable.Repeat(subscriptAddText, addText.Length)));
                

                //Set New Text
                txnote.Text = newText;
                FormattedText ftx2 = txnote.GetFormattedText();

                //Set Underline Status
                for (int i = 0; i &amp;lt; underlineStatuses.Count; i++)
                {
                    if (underlineStatuses[i] == true) { ftx2.SetUnderlineStatus(new TextRange(i, 1), true); }
                    else { { ftx2.SetUnderlineStatus(new TextRange(i, 1), false); } }

                    if (boldStatuses[i] == true) { ftx2.SetBoldStatus(new TextRange(i, 1), true); }
                    else { { ftx2.SetBoldStatus(new TextRange(i, 1), false); } }

                    if (italicStatuses[i] == true) { ftx2.SetItalicStatus(new TextRange(i, 1), true); }
                    else { { ftx2.SetItalicStatus(new TextRange(i, 1), false); } }

                    if (superscriptStatuses[i] == true) { ftx2.SetSuperscriptStatus(new TextRange(i, 1), true); }
                    else { { ftx2.SetSuperscriptStatus(new TextRange(i, 1), false); } }

                    if (subscriptStatuses[i] == true) { ftx2.SetSubscriptStatus(new TextRange(i, 1), true); }
                    else { { ftx2.SetSubscriptStatus(new TextRange(i, 1), false); } }
                }
                       

                txnote.SetFormattedText(ftx2);

            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 04:25:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-can-replace-text-in-textnote-by-keeping-same-formatting/m-p/10122501#M28957</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-02T04:25:09Z</dc:date>
    </item>
  </channel>
</rss>

