<?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 Region creates another instance of polygon in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8575930#M23613</link>
    <description>&lt;P&gt;Hi, I'm using this code below to create a region of an existing polygon. When I run this code it creates a region ok but it creates the region as a new entity and duplicates the polygon. Is there a way to covert the selected polygon into a region with out duplicating?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;CommandMethod("CreateRegion")&amp;gt;&lt;BR /&gt;Public Sub CreateRegion()&lt;BR /&gt;Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;Dim db As Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;'Dim copied As ObjectIdCollection = New ObjectIdCollection()&lt;/P&gt;
&lt;P&gt;'******Prompt user to select objects&lt;BR /&gt;Dim psr As PromptSelectionResult = doc.Editor.GetSelection()&lt;BR /&gt;'Dim acSSet As SelectionSet = psr.Value&lt;/P&gt;
&lt;P&gt;If psr.Status = PromptStatus.OK Then&lt;BR /&gt;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;Dim curves = New DBObjectCollection()&lt;BR /&gt;For Each obj As SelectedObject In psr.Value&lt;BR /&gt;curves.Add(tr.GetObject(obj.ObjectId, OpenMode.ForRead))&lt;BR /&gt;Dim regions = Region.CreateFromCurves(curves)&lt;BR /&gt;Dim curSpace As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)&lt;/P&gt;
&lt;P&gt;For Each region In regions&lt;BR /&gt;curSpace.AppendEntity(region)&lt;BR /&gt;tr.AddNewlyCreatedDBObject(region, True)&lt;BR /&gt;Next&lt;BR /&gt;Next&lt;BR /&gt;tr.Commit()&lt;BR /&gt;ed.WriteMessage("Region created")&lt;BR /&gt;End Using&lt;BR /&gt;End If&lt;BR /&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Shaban.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Feb 2019 05:24:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-02-06T05:24:01Z</dc:date>
    <item>
      <title>Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8575930#M23613</link>
      <description>&lt;P&gt;Hi, I'm using this code below to create a region of an existing polygon. When I run this code it creates a region ok but it creates the region as a new entity and duplicates the polygon. Is there a way to covert the selected polygon into a region with out duplicating?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;CommandMethod("CreateRegion")&amp;gt;&lt;BR /&gt;Public Sub CreateRegion()&lt;BR /&gt;Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;Dim db As Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;'Dim copied As ObjectIdCollection = New ObjectIdCollection()&lt;/P&gt;
&lt;P&gt;'******Prompt user to select objects&lt;BR /&gt;Dim psr As PromptSelectionResult = doc.Editor.GetSelection()&lt;BR /&gt;'Dim acSSet As SelectionSet = psr.Value&lt;/P&gt;
&lt;P&gt;If psr.Status = PromptStatus.OK Then&lt;BR /&gt;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;Dim curves = New DBObjectCollection()&lt;BR /&gt;For Each obj As SelectedObject In psr.Value&lt;BR /&gt;curves.Add(tr.GetObject(obj.ObjectId, OpenMode.ForRead))&lt;BR /&gt;Dim regions = Region.CreateFromCurves(curves)&lt;BR /&gt;Dim curSpace As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)&lt;/P&gt;
&lt;P&gt;For Each region In regions&lt;BR /&gt;curSpace.AppendEntity(region)&lt;BR /&gt;tr.AddNewlyCreatedDBObject(region, True)&lt;BR /&gt;Next&lt;BR /&gt;Next&lt;BR /&gt;tr.Commit()&lt;BR /&gt;ed.WriteMessage("Region created")&lt;BR /&gt;End Using&lt;BR /&gt;End If&lt;BR /&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Shaban.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 05:24:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8575930#M23613</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-02-06T05:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8575982#M23614</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to explicitly erase the curves used to create the region.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 06:14:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8575982#M23614</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-02-06T06:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586153#M23615</link>
      <description>&lt;P&gt;Do i do this before or after the tr.commit()??&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 21:14:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586153#M23615</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-02-10T21:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586225#M23616</link>
      <description>&lt;P&gt;Before. Transaction.Commit() saves the changes to Database done with the transaction.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 22:16:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586225#M23616</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-02-10T22:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586475#M23617</link>
      <description>&lt;P&gt;Hi, do you have some example code of explicitly erase the "curves" used to create the region.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks In advance&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 05:21:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586475#M23617</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-02-11T05:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Region creates another instance of polygon</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586579#M23618</link>
      <description>&lt;PRE&gt;        [CommandMethod("CreateRegion")]
        public static void CreateRegion()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curves = new DBObjectCollection();
                foreach (SelectedObject so in psr.Value)
                {
                    var id = so.ObjectId;
                    if (id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Curve))))
                    {
                        curves.Add(tr.GetObject(id, OpenMode.ForWrite));
                    }
                }
                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);
                }
                foreach(Curve curve in curves)
                {
                    curve.Erase();
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 07:00:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-creates-another-instance-of-polygon/m-p/8586579#M23618</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-02-11T07:00:47Z</dc:date>
    </item>
  </channel>
</rss>

