<?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 new Block from Existing Selection Set of Region objects or Region objects in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11913037#M1605</link>
    <description>&lt;OL&gt;
&lt;LI&gt;It's the AddRegion method, not the AddSelectionSet method. You need to iterate the selectionset and add the regions one at a time.&lt;/LI&gt;
&lt;LI&gt;You don't need to reference ActiveSelectionSet, just use selectionset1&lt;/LI&gt;
&lt;LI&gt;Your use of error handling needs working on. You need better control of how you use On Error Resume Next. As it is now, it will be masking other possible errors. Read the VBA help topic for the On Error statement&lt;/LI&gt;
&lt;LI&gt;It will help with your error handling if you don't try to put all tasks into one sub. Try to organize your code so that you only do one task in each sub. It will also make troubleshooting easier. If you debug a sub once, you don't need to do it again. For example, put your selectionset creation into a new sub. You can search this forum for my AddSelectionSet function.&lt;/LI&gt;
&lt;LI&gt;Create the new block def first. Then as you iterate the selectionset, you can append it to the block.&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Fri, 21 Apr 2023 15:40:22 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2023-04-21T15:40:22Z</dc:date>
    <item>
      <title>Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11911837#M1604</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;please note code below is partial code and not showing the entire thing hope you still can understand intent&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to convert all AcadRegion objects in selection set to new block&lt;/P&gt;&lt;P&gt;but i am getting nothing not sure what i am missing&lt;/P&gt;&lt;P&gt;for&amp;nbsp;selectedObjects i am getting Count value see screen shot = 20 items&lt;/P&gt;&lt;P&gt;but once i get to line 61 in code "set Blockobj" i am getting error&amp;nbsp;&lt;/P&gt;&lt;P&gt;any idea how to convert/add Region objects to Block&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jalalmousa_0-1682056993930.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1205035i22BDFDC581510BD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jalalmousa_0-1682056993930.png" alt="jalalmousa_0-1682056993930.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jalalmousa_1-1682057034854.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1205036i974841B39263EBA4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jalalmousa_1-1682057034854.png" alt="jalalmousa_1-1682057034854.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Add_Floor_Pattern_ID_Group()



On Error GoTo ErrorHandler
Set MyApp = GetObject(, "Autocad.Application")

ErrorHandler:
If Err.Description &amp;lt;&amp;gt; "" Then
Err.Clear
Set MyApp = CreateObject("Autocad.Application")
End If
MyApp.Visible = True
Set MyDWG = MyApp.ActiveDocument

Dim selectedObjects As Variant

dim AktIDPt as variant

aktpt = MyDWG.Utility.GetPoint(, "Place the Room Nr")

Set ID_Text = MyDWG.ModelSpace.AddText("ID_" &amp;amp; MyDWG.ModelSpace.Count, AktIDPt, UserForm_DrawToCalc.TBox_TextHight.Text)



On Error Resume Next
Set selectionSet1 = MyDWG.SelectionSets.Add("MySelectionSet1")


If Err Then
Err.Clear
Else
' selectionSet1.Delete
End If

Set selectionSet1 = MyDWG.SelectionSets.Item("MySelectionSet1")

Dim mode As Integer
Dim j As Integer

mode = acSelectionSetCrossingPolygon

selectionSet1.SelectByPolygon mode, pointsArray1



Dim i As Integer
For i = 0 To MyDWG.ActiveSelectionSet.Count - 1
If TypeOf selectedObjects(i) Is AcadRegion Then
Set appendObjs(4 + i) = MyDWG.ObjectIdToObject(selectedObjects(i).ObjectID)
selectedObjects(i).Layer = "RoomFloorPatternID"
End If
Next i



Dim blockObj As AcadBlock

Dim BID_Text As AcadBlock
Set BID_Text = MyDWG.Blocks.Add(aktpt, ID_Text.TextString)
Set blockObj = BID_Text.AddRegion(selectedObjects)



end sub
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 06:07:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11911837#M1604</guid>
      <dc:creator>jalal.mousa</dc:creator>
      <dc:date>2023-04-21T06:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11913037#M1605</link>
      <description>&lt;OL&gt;
&lt;LI&gt;It's the AddRegion method, not the AddSelectionSet method. You need to iterate the selectionset and add the regions one at a time.&lt;/LI&gt;
&lt;LI&gt;You don't need to reference ActiveSelectionSet, just use selectionset1&lt;/LI&gt;
&lt;LI&gt;Your use of error handling needs working on. You need better control of how you use On Error Resume Next. As it is now, it will be masking other possible errors. Read the VBA help topic for the On Error statement&lt;/LI&gt;
&lt;LI&gt;It will help with your error handling if you don't try to put all tasks into one sub. Try to organize your code so that you only do one task in each sub. It will also make troubleshooting easier. If you debug a sub once, you don't need to do it again. For example, put your selectionset creation into a new sub. You can search this forum for my AddSelectionSet function.&lt;/LI&gt;
&lt;LI&gt;Create the new block def first. Then as you iterate the selectionset, you can append it to the block.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 21 Apr 2023 15:40:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11913037#M1605</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-04-21T15:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914445#M1606</link>
      <description>&lt;P&gt;Hi Ed,&lt;/P&gt;&lt;P&gt;thanks for all notes but i still can't figure a way how&amp;nbsp;&lt;SPAN&gt;append it to the block&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;are you able to comment on this partial code how to fix it ? mainly line&amp;nbsp;Set objrr = BID_Text.AddRegion(obj)&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim BID_Text As AcadBlock
Dim blockObj As AcadBlock
Dim objrr As AcadRegion
Set BID_Text = MyDWG.Blocks.Add(aktpt, ID_Text.TextString)

For Each obj In selectionSet1
  
       
        If TypeOf obj Is AcadRegion Then
           
           
            Set objrr = BID_Text.AddRegion(obj)
            
        End If
    
    Next&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 07:37:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914445#M1606</guid>
      <dc:creator>jalal.mousa</dc:creator>
      <dc:date>2023-04-22T07:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914901#M1607</link>
      <description>&lt;P&gt;That's close, but the AddRegion method requires a Region object, not Object type, so you have to cast it first. See below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Dim BID_Text As AcadBlock
Dim blockObj As AcadBlock
Dim objrr As AcadRegion
Set BID_Text = MyDWG.Blocks.Add(aktpt, ID_Text.TextString)

For Each obj In selectionSet1       
        If TypeOf obj Is AcadRegion Then
           Set objrr = obj
           With objrr
             'You may need to adjust properties
             'such as insertion point, to be relative
             'to the block's insertion point
           End With
           BID_Text.AddRegion(objrr)            
        End If    
Next&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 15:50:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914901#M1607</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-04-22T15:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914932#M1608</link>
      <description>&lt;P&gt;Thanks ED&lt;/P&gt;&lt;P&gt;I tried it but got error with line" BID_Text.AddRegion (objrr)" in your proposed code, something is missing ?&lt;/P&gt;&lt;P&gt;I am getting Run Time Error 438 object does not support this property&lt;/P&gt;&lt;P&gt;also i added insertion point as you proposed&amp;nbsp; to use as reference to insert Block also i added Block reference but not sure if correct&lt;/P&gt;&lt;P&gt;kindly take another look&lt;/P&gt;&lt;LI-CODE lang="general"&gt;   Dim BID_Text As AcadBlock
 
 Dim blockObj As AcadBlock
 Dim objrr As AcadRegion
 Dim insertionPnt(0 To 2) As Double
Set BID_Text = MyDWG.Blocks.Add(aktpt, ID_Text.TextString)

For Each obj In selectionSet1
        If TypeOf obj Is AcadRegion Then
           
            Set objrr = obj
                 With objrr
                
   
                  'You may need to adjust properties
                  'such as insertion point, to be relative
                  'to the block's insertion point
             
                insertionPnt(0) = RoomMinPointX
                insertionPnt(1) = RoomMinPointY
                insertionPnt(2) = 0
                End With
           ' BID_Text.AddRegion(objrr)
           End If
    
    Next
' Insert the block
 Dim blockRefObj As AcadBlockReference
 Set blockRefObj = MyDWG.ModelSpace.InsertBlock(insertionPnt, BID_Text.ObjectName, 1#, 1#, 1#, 0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 16:36:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914932#M1608</guid>
      <dc:creator>jalal.mousa</dc:creator>
      <dc:date>2023-04-22T16:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914957#M1609</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14801"&gt;@Ed__Jobe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;The code would not work: the AddRegion() method requires an array of AcadObject/Entity, not a individual AcadObject/Entity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7225276"&gt;@jalal.mousa&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;With AutoCAD VBA/COM API, one cannot add an existing AcadEntity into a block definition (or Model/PaperSpace) via the AcadBlock.AddXXXXX() methods, for example, if you want to add a Line to a block definition, you do not create a Line first and then add it to the block definition via AddLine(). Rather, you pass the information required for creating a line, such as Start/EndPoint, and let the block definition create the entity behind the scene (via AddLine() method). The same applies to AddReagion() method: you DO NOT supply an array of Regions; instead, you pass an array of existing entities (line, polyline, arc... They must all on the same plane, of course) and the AddRegion() method will do the calculation behind the scene to determine how many closed areas these entities would form and then create an array of Regions accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, no, your code logic of selecting existing regions and adding them to a block definition does not work. You need find all existing regions' boundary as entities (closed polylines) and then add the array of these polylines with AddRegion() method, and let AutoCAD figures out how many regions could be formed from these closed polylines. However, since there is no way to get the Region's boundary, the logic of adding region(s) to a block definition will not work in VBA/Acad API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you do AutoCAD .NET API/ObjectARX API, then yes, you can add create an Entity, including Region, first and then add it into a block definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 17:07:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11914957#M1609</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-04-22T17:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Block from Existing Selection Set of Region objects or Region objects</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11915417#M1610</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp; Thanks. I hadn't tried it. I appreciate the correction.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2023 01:59:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-block-from-existing-selection-set-of-region-objects/m-p/11915417#M1610</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-04-23T01:59:18Z</dc:date>
    </item>
  </channel>
</rss>

