<?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: best way to process data when iterate each object in modelspace in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949785#M8900</link>
    <description>&lt;P&gt;Assume the argument Action&amp;lt;T&amp;gt; is one of the 5 tasks. Obviously, you need to call 5 times of the Database.ForEach&amp;lt;T&amp;gt;() extension method to get the 5 tasks done with each call needs to loop through the database's ModelSpace. I would not think simply looping through itself takes much time. rather it is what you do in the Action&amp;lt;T&amp;gt; really matters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to only loop through the modelspace once, the you can change the database extension method signature, by passing in a collection of Action&amp;lt;T&amp;gt;,&amp;nbsp; like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;public static void ForEach&amp;lt;T&amp;gt;(this Database database, IEnumerable&amp;lt;Action&amp;lt;T&amp;gt;&amp;gt; actions)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously you also need to modify the extension method&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BlockTableRecord.ForEach(this BlockTableRecord space, Transaction tran, IEnumberable&amp;lt;Action&amp;lt;T&amp;gt;&amp;gt; actions)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 19:03:04 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2023-05-08T19:03:04Z</dc:date>
    <item>
      <title>best way to process data when iterate each object in modelspace</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949609#M8899</link>
      <description>&lt;P&gt;hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just built a app. now I like to make some re-factory. I found I iterate all objects of whole modelspace in 5 places. it will take lot of time for big drawing. I like to change to scan modelspace once.&amp;nbsp;&lt;/P&gt;&lt;P&gt;also make the 5 tasks configurable. depend on the config file, I can run 1 task, or 5 tasks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;how should I design the code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is code I use, which should from&amp;nbsp;Scott McFarlane and Tony T.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public static void ForEach&amp;lt;T&amp;gt;(this Database database, Action&amp;lt;T&amp;gt; action)
            where T : Entity
        {
            database.UsingModelSpace((tr, modelSpace) =&amp;gt; modelSpace.ForEach(tr, action));
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 17:35:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949609#M8899</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2023-05-08T17:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: best way to process data when iterate each object in modelspace</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949785#M8900</link>
      <description>&lt;P&gt;Assume the argument Action&amp;lt;T&amp;gt; is one of the 5 tasks. Obviously, you need to call 5 times of the Database.ForEach&amp;lt;T&amp;gt;() extension method to get the 5 tasks done with each call needs to loop through the database's ModelSpace. I would not think simply looping through itself takes much time. rather it is what you do in the Action&amp;lt;T&amp;gt; really matters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to only loop through the modelspace once, the you can change the database extension method signature, by passing in a collection of Action&amp;lt;T&amp;gt;,&amp;nbsp; like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;public static void ForEach&amp;lt;T&amp;gt;(this Database database, IEnumerable&amp;lt;Action&amp;lt;T&amp;gt;&amp;gt; actions)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously you also need to modify the extension method&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BlockTableRecord.ForEach(this BlockTableRecord space, Transaction tran, IEnumberable&amp;lt;Action&amp;lt;T&amp;gt;&amp;gt; actions)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 19:03:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949785#M8900</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-05-08T19:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: best way to process data when iterate each object in modelspace</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949817#M8901</link>
      <description>&lt;P&gt;thank you,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that's what I thought at beginning. but it only work with simple task. for some tasks are really complicate,&amp;nbsp;&lt;/P&gt;&lt;P&gt;a. before ForEach, I need initialize&amp;nbsp;&lt;/P&gt;&lt;P&gt;b. during ForEach, I need filter and action, and filter and action are different between task&lt;/P&gt;&lt;P&gt;c. after ForEach, I need do different kind of calculation according to the data I collection in the ForEach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what's the best way to solve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a million&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 19:21:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-way-to-process-data-when-iterate-each-object-in-modelspace/m-p/11949817#M8901</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2023-05-08T19:21:50Z</dc:date>
    </item>
  </channel>
</rss>

