<?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: Edit multiple lines attribute in dynamic block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7550883#M28954</link>
    <description>&lt;P&gt;The edit portion of this solution is not right. &amp;nbsp;Autocad uses \\P instead of \\n. &amp;nbsp;\\P in C# is not easy to deal with. &amp;nbsp;I felt I should update my solution so it doesn't keep me awake at night - just in case someone (like me who forgets) finds this post in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my case I need to edit the last line of attribute mtext but I don't know how many text lines are above it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed create to: &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;string attribtext = "line 1\\Pline 2";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The "edit":&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;MText oldtext = attref.MTextAttribute;
DBObjectCollection objs = new DBObjectCollection();
oldtext.Explode(objs);
int i = 0;
string after = string.Empty;
foreach (DBObject obj in objs)
{
    DBText dt = (DBText)obj;
    if (i &amp;lt; objs.Count - 1)
        after += dt.TextString + "\\P";
    i++;
    dt.Dispose();
}// foreach exploded text obj
string newpart = "new last line";
after += newpart;
MText mt = attref.MTextAttribute;
mt.Contents = after;
attref.MTextAttribute = mt;
attref.UpgradeMTextAttribute;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Nov 2017 19:52:11 GMT</pubDate>
    <dc:creator>fieldguy</dc:creator>
    <dc:date>2017-11-16T19:52:11Z</dc:date>
    <item>
      <title>Edit multiple lines attribute in dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7546738#M28950</link>
      <description>&lt;P&gt;We use a block definition that includes custom properties and 2 attribute definitions. &amp;nbsp;1 of the attribute defs has "Multiple lines" = "Yes". &amp;nbsp;When the attribute is added, the textstring is set to "first line \n second line". &amp;nbsp;I test when the att def is created and IsMTextAttribute is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This all works until the attribute has to be edited. &amp;nbsp;The attref textstring does not contain "\n" or "\p". &amp;nbsp;Am I missing something? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried attref.TextString and MText mt = attref.MTextAttribute. &amp;nbsp;Neither the textstring or the mt.Contents contain any newline character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;edit&amp;gt; the second line is the area of a closed pline. &amp;nbsp;i need to edit the area if it changes. &amp;nbsp;I am using Civil 3D 2016&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:27:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7546738#M28950</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-11-15T16:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Edit multiple lines attribute in dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547074#M28951</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/81963"&gt;@fieldguy&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;We use a block definition that includes custom properties and 2 attribute definitions. &amp;nbsp;1 of the attribute defs has "Multiple lines" = "Yes". &amp;nbsp;When the attribute is added, the textstring is set to "first line \n second line". &amp;nbsp;I test when the att def is created and IsMTextAttribute is true.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This all works until the attribute has to be edited. &amp;nbsp;The attref textstring does not contain "\n" or "\p". &amp;nbsp;Am I missing something? &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried attref.TextString and MText mt = attref.MTextAttribute. &amp;nbsp;Neither the textstring or the mt.Contents contain any newline character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;edit&amp;gt; the second line is the area of a closed pline. &amp;nbsp;i need to edit the area if it changes. &amp;nbsp;I am using Civil 3D 2016&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You need to get the value of the AttributeReference's MTextAttribute (which is an MText object), and use that to edit the text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After you've edited the returned MText, you have to assign it back to the MTextAttribute property of the AttributeReference.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 18:15:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547074#M28951</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-11-15T18:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Edit multiple lines attribute in dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547610#M28952</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks - I see what happened. &amp;nbsp;When I created the attref I used attref.TextString instead of attref.MTextAttribute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create the attref value:&lt;/P&gt;
&lt;P&gt;string attribtext = "line 1\nline 2";&lt;/P&gt;
&lt;P&gt;MText attval = attref.MtextAtttribute;&lt;/P&gt;
&lt;P&gt;attval.Contents = attribtext;&lt;/P&gt;
&lt;P&gt;attref.MTextAttribute = attval;&lt;/P&gt;
&lt;P&gt;attref.UpdateMTextAttribute();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To edit the attref value:&lt;/P&gt;
&lt;P&gt;MText old = attref.MTextAttribute;&lt;/P&gt;
&lt;P&gt;string[] parts = old.Split('\n');&lt;/P&gt;
&lt;P&gt;string newpart = "new line 2";&lt;/P&gt;
&lt;P&gt;string after = parts[0] + "\n" + newpart;&lt;/P&gt;
&lt;P&gt;MText new = attref.MTextAttribute;&lt;/P&gt;
&lt;P&gt;new.Contents = after;&lt;/P&gt;
&lt;P&gt;attref.MTextAttribute = new;&lt;/P&gt;
&lt;P&gt;attref.UpgradeMTextAttribute();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 20:57:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547610#M28952</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-11-15T20:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Edit multiple lines attribute in dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547966#M28953</link>
      <description>&lt;P&gt;LOL&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 23:15:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7547966#M28953</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-11-15T23:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Edit multiple lines attribute in dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7550883#M28954</link>
      <description>&lt;P&gt;The edit portion of this solution is not right. &amp;nbsp;Autocad uses \\P instead of \\n. &amp;nbsp;\\P in C# is not easy to deal with. &amp;nbsp;I felt I should update my solution so it doesn't keep me awake at night - just in case someone (like me who forgets) finds this post in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my case I need to edit the last line of attribute mtext but I don't know how many text lines are above it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed create to: &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;string attribtext = "line 1\\Pline 2";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The "edit":&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;MText oldtext = attref.MTextAttribute;
DBObjectCollection objs = new DBObjectCollection();
oldtext.Explode(objs);
int i = 0;
string after = string.Empty;
foreach (DBObject obj in objs)
{
    DBText dt = (DBText)obj;
    if (i &amp;lt; objs.Count - 1)
        after += dt.TextString + "\\P";
    i++;
    dt.Dispose();
}// foreach exploded text obj
string newpart = "new last line";
after += newpart;
MText mt = attref.MTextAttribute;
mt.Contents = after;
attref.MTextAttribute = mt;
attref.UpgradeMTextAttribute;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Nov 2017 19:52:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/edit-multiple-lines-attribute-in-dynamic-block/m-p/7550883#M28954</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-11-16T19:52:11Z</dc:date>
    </item>
  </channel>
</rss>

