<?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 : create many regions at once in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917815#M32451</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public void Test()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            var selection = ed.GetSelection();
            if (selection.Status != PromptStatus.OK)
                return;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var curves = new DBObjectCollection();
                foreach (SelectedObject obj in selection.Value)
                {
                    curves.Add(tr.GetObject(obj.ObjectId, OpenMode.ForRead));
                }
                var regions = Region.CreateFromCurves(curves);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (Region region in regions)
                {
                    curSpace.AppendEntity(region);
                    tr.AddNewlyCreatedDBObject(region, true);
                }
                tr.Commit();
                ed.WriteMessage($"\nCreated {regions.Count} region(s).");
            }
        }&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Mar 2017 07:26:30 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2017-03-03T07:26:30Z</dc:date>
    <item>
      <title>create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917772#M32450</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;The DWG have thousands of connecting flat lines. By using the REGION command we can instantly create bounded regions from the lines.&lt;/P&gt;&lt;P&gt;How can I do the same with dot net?&lt;/P&gt;&lt;P&gt;The knowledge network shows a single&amp;nbsp;path example like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DBObjectCollection myRegionColl = new DBObjectCollection();
myRegionColl = Region.CreateFromCurves(acDBObjColl);
Region acRegion = myRegionColl[0] as Region;
acBlkTblRec.AppendEntity(acRegion);&lt;/PRE&gt;&lt;P&gt;where the collection was a single circle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess ... Region acRegion = myRegionColl[0] as Region;&amp;nbsp; is expecting a single bounded planar object ... and will not work with thousands of lines&lt;/P&gt;&lt;P&gt;Thx,&lt;/P&gt;&lt;P&gt;Kevin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 06:56:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917772#M32450</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T06:56:51Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917815#M32451</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public void Test()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            var selection = ed.GetSelection();
            if (selection.Status != PromptStatus.OK)
                return;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var curves = new DBObjectCollection();
                foreach (SelectedObject obj in selection.Value)
                {
                    curves.Add(tr.GetObject(obj.ObjectId, OpenMode.ForRead));
                }
                var regions = Region.CreateFromCurves(curves);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (Region region in regions)
                {
                    curSpace.AppendEntity(region);
                    tr.AddNewlyCreatedDBObject(region, true);
                }
                tr.Commit();
                ed.WriteMessage($"\nCreated {regions.Count} region(s).");
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2017 07:26:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917815#M32451</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-03-03T07:26:30Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917823#M32452</link>
      <description>&lt;P&gt;Thx Gilles ... neat clean example... very nice&amp;nbsp;&amp;nbsp; : )&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 07:33:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917823#M32452</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T07:33:12Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917898#M32453</link>
      <description>&lt;P&gt;Gilles, I hope you have 30 odd minutes to check this. I have attached a DWG. top left are 3D lines, left of that a copy of the lines flattened, left of that the same lines converted to regions with the region command.&lt;/P&gt;&lt;P&gt;next row, copies of the same flattened lines; on running code on final copy of lines, error: invalid.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Looks like the region command is forgiving and skips invalid line objects; but we need to check for validity before attempting:&lt;/P&gt;&lt;P&gt;var regions = Region.CreateFromCurves(curves)&lt;/P&gt;&lt;P&gt;... how do we check for validity?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 08:13:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917898#M32453</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T08:13:02Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917997#M32454</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;I took a look, but I did not find the cause of the error.&lt;/SPAN&gt; &lt;SPAN&gt;By making several successive selections one succeeds in creating all the regions.&lt;/SPAN&gt;&lt;BR /&gt;I'm sorry but I do not have more time to devote to that now.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 09:06:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6917997#M32454</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-03-03T09:06:07Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918034#M32455</link>
      <description>&lt;P&gt;Gilles, thx for continuing to help with this,there's no rush in solving this, we will solve this eventually...&lt;/P&gt;&lt;P&gt;I went back and applied the region command... check the command line text...&lt;/P&gt;&lt;P&gt;Select objects: Specify opposite corner: 6554 found&lt;BR /&gt;Select objects:&lt;BR /&gt;2188 loops extracted.&lt;BR /&gt;3 loops rejected.&lt;BR /&gt;Vertex with degree greater than two : 3 loops.&lt;BR /&gt;2185 Regions created.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;So, there's an indicator here... Vertex with degree greater than two: 3 loops and those 3 loops rejected.&lt;/P&gt;&lt;P&gt;I just need to write code to do the same rejection from the object collection (curves) ...&lt;/P&gt;&lt;P&gt;Vertex with degree greater than two ... hmmmmm how do we check for that in code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 09:17:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918034#M32455</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T09:17:43Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918092#M32456</link>
      <description>&lt;P&gt;I just used overkill prior to region, enabled "combine co-linear objects that partially overlap" and "combine co-linear objects when aligned end to end". on using region after this overkill, the number of rejected increases from 3 to 14, same message "Vertex with degree greater than two".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 09:43:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918092#M32456</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T09:43:07Z</dc:date>
    </item>
    <item>
      <title>Re : create many regions at once</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918161#M32457</link>
      <description>&lt;P&gt;I am going to cheat and return to the awful SEND COMMAND eeeuuuggghhh&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;Autodesk api developers please improve the Region.CreateFromCurves method to work exactly the same as the region command (rejecting strange inconsistencies) ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;List&amp;lt;ObjectId&amp;gt; ids = new List&amp;lt;ObjectId&amp;gt;();
ids.AddRange(selection.Value.GetObjectIds());
ed.SetImpliedSelection(ids.ToArray());
doc.SendStringToExecute(".region p  ", false, false, false);&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2017 10:16:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-many-regions-at-once/m-p/6918161#M32457</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-03T10:16:52Z</dc:date>
    </item>
  </channel>
</rss>

