<?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 : Slow Processing Multileaders in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5448598#M41931</link>
    <description>&lt;P&gt;Hi Brent,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, this does not answer your query on why its slower, but the right way to&amp;nbsp;change the MLeader text is to assign a MText to it and not change its contents directly. As i understand,&amp;nbsp;the MLeader would not reflect the change to its contents if that is not the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am not sure why would want to change the contents rather than assign MLeader's MText.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sample code that you can try :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = activeDoc.Database;&lt;BR /&gt;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;&lt;BR /&gt;PromptEntityOptions peo = new PromptEntityOptions("Select an entity : ");&lt;BR /&gt;PromptEntityResult per = ed.GetEntity(peo);&lt;BR /&gt;if (per.Status != PromptStatus.OK)&lt;BR /&gt; return;&lt;BR /&gt;ObjectId entId = per.ObjectId;&lt;BR /&gt;&lt;BR /&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt; MLeader ml = tr.GetObject(entId, OpenMode.ForWrite) as MLeader;&lt;BR /&gt; if (ml != null)&lt;BR /&gt; {&lt;BR /&gt; string originalText = ml.MText.Contents;&lt;BR /&gt; &lt;BR /&gt; // Does not work&lt;BR /&gt; ml.MText.Contents = originalText.ToUpper();&lt;BR /&gt;&lt;BR /&gt; // Works&lt;BR /&gt; //MText mt = new MText();&lt;BR /&gt; //mt.Contents = originalText.ToUpper();&lt;BR /&gt; //ml.MText = mt;&lt;BR /&gt; }&lt;BR /&gt; tr.Commit();&lt;BR /&gt;} &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Regards,&lt;/P&gt;
&lt;P&gt;Balaji&lt;/P&gt;</description>
    <pubDate>Fri, 19 Dec 2014 08:45:48 GMT</pubDate>
    <dc:creator>Balaji_Ram</dc:creator>
    <dc:date>2014-12-19T08:45:48Z</dc:date>
    <item>
      <title>Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5444505#M41926</link>
      <description>&lt;P&gt;Afternoon Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a drawing number transposition plugin that will iterate all MText, DText, MLeaders etc in a drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below code flies through the Mtext, but struggles on the MLeader.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static void process_QualifiedNumbers()
            {
            DateTime start = DateTime.Now;
            processMText_Qualified();
            DateTime end = DateTime.Now;
            Ed.WriteMessage("\n{0} Mtext processed in {1}s", MText.Count, end.Subtract(start).TotalSeconds);

            start = DateTime.Now;
            processMLeader_Qualified();
            end = DateTime.Now;
            Ed.WriteMessage("\n{0} MLeaders processed in {1}s", Multileaders.Count, end.Subtract(start).TotalSeconds);
            }

        private static void processMText_Qualified()
            {
            foreach (MText mt in MText)
                {
                foreach (DrawingNumber dwg in DrawingNumbers.List)
                    {
                    if (mt.Contents.Contains(dwg.ProjectNumber))
                        {
                        mt.Contents = mt.Contents.Replace(dwg.ProjectNumber, dwg.ClientNumber);
                        }
                    }
                }
            }

        private static void processMLeader_Qualified()
            {
            foreach (MLeader ml in Multileaders)
                {
                foreach (DrawingNumber dwg in DrawingNumbers.List)
                    {
                    if (ml.MText.Contents.Contains(dwg.ProjectNumber))
                        {
                        ml.MText.Contents = ml.MText.Contents.Replace(dwg.ProjectNumber, dwg.ClientNumber);
                        }
                    }
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is&lt;/P&gt;&lt;P&gt;8 Mtext processed in 0.0468003s&lt;BR /&gt;22 MLeaders processed in 71.9402444s&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however the MLeader text does not change.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I doing something wrong? Is there a way to speed it up and get the MLeader text to change?&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;Brent&lt;/P&gt;</description>
      <pubDate>Tue, 16 Dec 2014 07:38:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5444505#M41926</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2014-12-16T07:38:52Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445293#M41927</link>
      <description>&lt;P&gt;Reading Contents property need some processing because the formatiing data used for word wrap calculations is removed before the string is copied. So may be you should cache the text. You can also remove the call to Contains: if there is no match, Replace will do nothing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static void processMLeader_Qualified()
{
  foreach (MLeader ml in Multileaders)
  {
    MText mText = ml.MText;
    string contents = mText.Contents;    
    foreach (DrawingNumber dwg in DrawingNumbers.List)
    {&lt;BR /&gt;      mText.Contents = contents.Replace(dwg.ProjectNumber, dwg.ClientNumber);
    }
  }
}&lt;/PRE&gt;&lt;P&gt;You should also use System.Diagnostics.StopWatch instead of DateTime.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Dec 2014 19:27:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445293#M41927</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2014-12-16T19:27:44Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445694#M41928</link>
      <description>&lt;P&gt;Thanks &lt;SPAN style="text-decoration: underline;"&gt;FRFR1426.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The contains does seem redundant doesnt it - Thanks for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the Contents property, would that not apply to MText too? The MText is being processed in next to no time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2014 01:39:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445694#M41928</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2014-12-17T01:39:26Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445851#M41929</link>
      <description>&lt;P&gt;Yes, but who knows? It can only comes from the MText or the Contents properties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just enclose your code with a pair of StopWatch.StartNew/Debug.Print:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var sw = StopWatch.StartNew();
MText mText = ml.MText;
Debug.Print("Elapsed ms for MText property: {0} ms", sw.ElapsedMilliseconds);&lt;BR /&gt;sw.Restart();&lt;BR /&gt;string contents = mText.Contents;&amp;nbsp;&lt;BR /&gt;Debug.Print("Elapsed ms for Contents property: {0} ms", sw.ElapsedMilliseconds);&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2014 07:35:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5445851#M41929</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2014-12-17T07:35:15Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5447022#M41930</link>
      <description>&lt;P&gt;Interestingly, when the below code processes&amp;nbsp;in no time.&lt;/P&gt;&lt;P&gt;22 MLeaders processed in 0.0018731s&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static void processMLeaders_Qualified()
            {
            foreach (MLeader ml in Multileaders)
                {
                MText mt = ml.MText;
                foreach (DrawingNumber dwg in DrawingNumbers.List)
                    {
                    mt.Contents = mt.Contents.Replace(dwg.ProjectNumber, dwg.ClientNumber);
                    //ml.MText = mt;
                    }
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, once we remove the comment to make then line&lt;/P&gt;&lt;P&gt;ml.MText = mt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code process takes a lot longer&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;22 MLeaders processed in 55.1823468s&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still can't figure out why.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2014 02:53:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5447022#M41930</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2014-12-18T02:53:27Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5448598#M41931</link>
      <description>&lt;P&gt;Hi Brent,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, this does not answer your query on why its slower, but the right way to&amp;nbsp;change the MLeader text is to assign a MText to it and not change its contents directly. As i understand,&amp;nbsp;the MLeader would not reflect the change to its contents if that is not the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am not sure why would want to change the contents rather than assign MLeader's MText.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sample code that you can try :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = activeDoc.Database;&lt;BR /&gt;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;&lt;BR /&gt;PromptEntityOptions peo = new PromptEntityOptions("Select an entity : ");&lt;BR /&gt;PromptEntityResult per = ed.GetEntity(peo);&lt;BR /&gt;if (per.Status != PromptStatus.OK)&lt;BR /&gt; return;&lt;BR /&gt;ObjectId entId = per.ObjectId;&lt;BR /&gt;&lt;BR /&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt; MLeader ml = tr.GetObject(entId, OpenMode.ForWrite) as MLeader;&lt;BR /&gt; if (ml != null)&lt;BR /&gt; {&lt;BR /&gt; string originalText = ml.MText.Contents;&lt;BR /&gt; &lt;BR /&gt; // Does not work&lt;BR /&gt; ml.MText.Contents = originalText.ToUpper();&lt;BR /&gt;&lt;BR /&gt; // Works&lt;BR /&gt; //MText mt = new MText();&lt;BR /&gt; //mt.Contents = originalText.ToUpper();&lt;BR /&gt; //ml.MText = mt;&lt;BR /&gt; }&lt;BR /&gt; tr.Commit();&lt;BR /&gt;} &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Regards,&lt;/P&gt;
&lt;P&gt;Balaji&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2014 08:45:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5448598#M41931</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2014-12-19T08:45:48Z</dc:date>
    </item>
    <item>
      <title>Re : Slow Processing Multileaders</title>
      <link>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5450431#M41932</link>
      <description>&lt;P&gt;All solved - Was calling the Mleader.MText multiple times slowing it down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way only calls it once.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static void processMLeaders_Qualified()
            {
            foreach (MLeader ml in Multileaders)
                {
                MText mt = ml.MText;

                foreach (KeyValuePair&amp;lt;string, string&amp;gt; pair in DrawingNumbers.List)
                    {
                    mt.Contents = mt.Contents.Replace(pair.Key, pair.Value);
                    ml.MText = mt;
                    }
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers Balaji for the help in pointing that out.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2014 11:18:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/slow-processing-multileaders/m-p/5450431#M41932</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2014-12-22T11:18:30Z</dc:date>
    </item>
  </channel>
</rss>

