<?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: Combine multiple regions and use the 'Union' command to merge them all at once in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/combine-multiple-regions-and-use-the-union-command-to-merge-them/m-p/12852469#M3538</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;From the tests I did calling the UNION comand (directly or from code) is not faster than calling the Region.BooleanOperation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST1")]
public void Test1()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    var filter = new SelectionFilter(new[] { new TypedValue(0, "REGION") });
    var selection = ed.GetSelection(filter);
    if (selection.Status == PromptStatus.OK)
    {
        var stopwatch = new Stopwatch();
        stopwatch.Start();
        using (var tr = db.TransactionManager.StartTransaction())
        {
            selection.Value.GetObjectIds()
                .Select (id =&amp;gt; (Region)tr.GetObject(id, OpenMode.ForWrite))
                .Aggregate((r1, r2) =&amp;gt;
                {
                    r1.BooleanOperation(BooleanOperationType.BoolUnite, r2);
                    return r1;
                });
            tr.Commit();
        }
        stopwatch.Stop();
        ed.WriteMessage($"\nElapsed millisecond: {stopwatch.ElapsedMilliseconds} to union {selection.Value.Count} regions.");
    }
}

[CommandMethod("TEST2")]
public void Test2()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    var filter = new SelectionFilter(new[] { new TypedValue(0, "REGION") });
    var selection = ed.GetSelection(filter);
    if (selection.Status == PromptStatus.OK)
    {
        var stopwatch = new Stopwatch();
        stopwatch.Start();
        ed.Command("_.UNION", selection.Value, "");
        stopwatch.Stop();
        ed.WriteMessage($"\nElapsed millisecond: {stopwatch.ElapsedMilliseconds} to union {selection.Value.Count} regions.");
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2024 21:21:57 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2024-06-20T21:21:57Z</dc:date>
    <item>
      <title>Combine multiple regions and use the 'Union' command to merge them all at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/combine-multiple-regions-and-use-the-union-command-to-merge-them/m-p/12852390#M3537</link>
      <description>&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;In civil engineering, I have a quantity that can vary from 4,000 to 13,000 Regions to unite. I've already tested it with the command that adds one by one, but it takes a lot of time. Using this option, I can select several elements of the project and unite everything in one second. I would like to know if anyone has used this Union via .NET C# to add a set of elements.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="artillis_prado_0-1718912983294.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1378412iFEC37A98E7D16B62/image-size/medium?v=v2&amp;amp;px=400" role="button" title="artillis_prado_0-1718912983294.png" alt="artillis_prado_0-1718912983294.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 19:58:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/combine-multiple-regions-and-use-the-union-command-to-merge-them/m-p/12852390#M3537</guid>
      <dc:creator>artillis_prado</dc:creator>
      <dc:date>2024-06-20T19:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple regions and use the 'Union' command to merge them all at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/combine-multiple-regions-and-use-the-union-command-to-merge-them/m-p/12852469#M3538</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;From the tests I did calling the UNION comand (directly or from code) is not faster than calling the Region.BooleanOperation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST1")]
public void Test1()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    var filter = new SelectionFilter(new[] { new TypedValue(0, "REGION") });
    var selection = ed.GetSelection(filter);
    if (selection.Status == PromptStatus.OK)
    {
        var stopwatch = new Stopwatch();
        stopwatch.Start();
        using (var tr = db.TransactionManager.StartTransaction())
        {
            selection.Value.GetObjectIds()
                .Select (id =&amp;gt; (Region)tr.GetObject(id, OpenMode.ForWrite))
                .Aggregate((r1, r2) =&amp;gt;
                {
                    r1.BooleanOperation(BooleanOperationType.BoolUnite, r2);
                    return r1;
                });
            tr.Commit();
        }
        stopwatch.Stop();
        ed.WriteMessage($"\nElapsed millisecond: {stopwatch.ElapsedMilliseconds} to union {selection.Value.Count} regions.");
    }
}

[CommandMethod("TEST2")]
public void Test2()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    var filter = new SelectionFilter(new[] { new TypedValue(0, "REGION") });
    var selection = ed.GetSelection(filter);
    if (selection.Status == PromptStatus.OK)
    {
        var stopwatch = new Stopwatch();
        stopwatch.Start();
        ed.Command("_.UNION", selection.Value, "");
        stopwatch.Stop();
        ed.WriteMessage($"\nElapsed millisecond: {stopwatch.ElapsedMilliseconds} to union {selection.Value.Count} regions.");
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 21:21:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/combine-multiple-regions-and-use-the-union-command-to-merge-them/m-p/12852469#M3538</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-06-20T21:21:57Z</dc:date>
    </item>
  </channel>
</rss>

