<?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: SelectByPolygon Method (ActiveX) Selectselection set , select all region (objects inside polyline points) in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11796595#M1775</link>
    <description>&lt;P&gt;You're forgetting basic selection procedures, the difference between a selection window and a crossing window. Help for the &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-D8002585-5D08-45E2-AF6C-6E894FA3D463" target="_blank" rel="noopener"&gt;SelectByPolygon&lt;/A&gt; method explains that you want to use the acSelectionSetCrossingPolygon constant.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2023 16:57:22 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2023-03-03T16:57:22Z</dc:date>
    <item>
      <title>SelectByPolygon Method (ActiveX) Selectselection set , select all region (objects inside polyline points)</title>
      <link>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11795134#M1774</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;
&lt;P&gt;i have a code that select/set closed polyline and once i extract coordinates i am trying to set selection set but &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;i am getting nothing in line&amp;nbsp;selectionSet.SelectByPolygon acSelectionSetWindowPolygon, pointsArray&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;i have not copied the entire code so some definitions maybe missing (please ignore)&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Dim selectionSet As AcadSelectionSet ' Selection set to store the selected objects


Dim AktIDPt As Variant
'Dim MyDWG As AcadDocument
Dim AcadApp As Object
Dim AcadDoc As Object

Dim ThisDrawing As Object

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 index As Integer

Dim ent As AcadEntity
Dim PL, Pl_Save As AcadLWPolyline

Dim points As Variant

MyDWG.Utility.GetEntity ent, pp, "Select Tile / Shpae must be polyline: "

If TypeOf ent Is AcadLWPolyline Then

If ent .closed = True Then

Set PL = ent

End If


Dim v As Variant
v = PL.Coordinates

Dim i As Integer
L = UBound(v)
index = 0
For i = 0 To UBound(v) Step 2
points(index) = v(i)
points(index + 1) = v(i + 1)
points(index + 2) = 0

index = index + 3
Next
points(index) = points(0)
points(index + 1) = points(1)
points(index + 2) = 0


savepoints = points


End If


Set selectionSet = MyDWG.SelectionSets.Add("MySelectionSet")


Dim mode As Integer
Dim pointsArray() As Double

mode = acSelectionSetWindowPolygon

pointsArray = points
selectionSet.SelectByPolygon acSelectionSetWindowPolygon, pointsArray&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**Moderator edit: Moved code to code window. Please&amp;nbsp; use the &amp;lt;/&amp;gt; button to access the code window.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 15:56:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11795134#M1774</guid>
      <dc:creator>jalal.mousa</dc:creator>
      <dc:date>2023-03-03T15:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: SelectByPolygon Method (ActiveX) Selectselection set , select all region (objects inside polyline points)</title>
      <link>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11796595#M1775</link>
      <description>&lt;P&gt;You're forgetting basic selection procedures, the difference between a selection window and a crossing window. Help for the &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-D8002585-5D08-45E2-AF6C-6E894FA3D463" target="_blank" rel="noopener"&gt;SelectByPolygon&lt;/A&gt; method explains that you want to use the acSelectionSetCrossingPolygon constant.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 16:57:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11796595#M1775</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-03-03T16:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: SelectByPolygon Method (ActiveX) Selectselection set , select all region (objects inside polyline points)</title>
      <link>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11807793#M1776</link>
      <description>&lt;P&gt;Hi Ed,&lt;/P&gt;&lt;P&gt;hope you can help me i am getting error "object variable or with block variable not set" for line&amp;nbsp;&lt;/P&gt;&lt;P&gt;selectionSet.SelectByPolygon mode, pointsArray&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;i Noticed that first time it runs it return values see screen shot Selection set, does that means i need to delete selection set everytime it runs ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;point Array have value see screen shot attached&lt;/P&gt;&lt;P&gt;also autocad attached&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;are you able to advise what is the issue. below full updated code i am using&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub Get_List_of_regions_in_Room()&lt;/P&gt;&lt;P&gt;Dim Test As Boolean&lt;BR /&gt;Dim selectionSet As AcadSelectionSet ' Selection set to store the selected objects&lt;BR /&gt;Dim Flooringshape1 As AcadEntity&lt;BR /&gt;Dim sarea As Double&lt;BR /&gt;Dim Slength As Double&lt;BR /&gt;Dim ent As AcadEntity&lt;BR /&gt;Dim MyDWG As AcadDocument&lt;BR /&gt;Dim pp As AcadLWPolyline&lt;BR /&gt;Dim pointsArray() As Double&lt;BR /&gt;Dim index As Integer&lt;BR /&gt;Dim Flooringshape As AcadEntity&lt;/P&gt;&lt;P&gt;Dim PL, Pl_Save As AcadLWPolyline&lt;/P&gt;&lt;P&gt;On Error GoTo ErrorHandler&lt;BR /&gt;Set MyApp = GetObject(, "Autocad.Application")&lt;BR /&gt;ErrorHandler:&lt;BR /&gt;If Err.Description &amp;lt;&amp;gt; "" Then&lt;BR /&gt;&lt;BR /&gt;Err.Clear&lt;BR /&gt;Set MyApp = CreateObject("Autocad.Application")&lt;BR /&gt;End If&lt;BR /&gt;MyApp.Visible = True&lt;BR /&gt;Set MyDWG = MyApp.ActiveDocument&lt;/P&gt;&lt;P&gt;' select poly Line&lt;BR /&gt;MyDWG.Utility.GetEntity ent, pp, "Select Tile / Shpae must be polyline: "&lt;/P&gt;&lt;P&gt;If TypeOf ent Is AcadLWPolyline Then&lt;/P&gt;&lt;P&gt;If ent.closed = True Then&lt;BR /&gt;Set Room = ent&lt;BR /&gt;End If&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set Flooringshape1 = Room&lt;BR /&gt;Test = True&lt;BR /&gt;If TypeOf Flooringshape1 Is AcadCircle Then&lt;BR /&gt;Set Floorcircle = Flooringshape&lt;BR /&gt;circleCen(0) = Floorcircle.center(0)&lt;BR /&gt;circleCen(1) = Floorcircle.center(1)&lt;/P&gt;&lt;P&gt;circleRad = Floorcircle.radius&lt;BR /&gt;&lt;BR /&gt;ElseIf TypeOf Flooringshape1 Is AcadLWPolyline Then&lt;BR /&gt;&lt;BR /&gt;If Flooringshape1.closed = True Then&lt;BR /&gt;Set PL = Flooringshape1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;sarea = PL.area&lt;BR /&gt;Slength = PL.Length&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ReDim points(UBound(PL.Coordinates) + (UBound(PL.Coordinates) + 1) / 2 + 3) As Double&lt;BR /&gt;ReDim savepoints(UBound(PL.Coordinates) + (UBound(PL.Coordinates) + 1) / 2 + 3) As Double&lt;BR /&gt;Dim Roompoints() As Double&lt;BR /&gt;&lt;BR /&gt;'Dim v As Variant&lt;BR /&gt;v = PL.Coordinates&lt;BR /&gt;End If&lt;BR /&gt;Dim i As Integer&lt;BR /&gt;L = UBound(v)&lt;BR /&gt;&lt;BR /&gt;index = 0&lt;BR /&gt;For i = 0 To UBound(v) Step 2&lt;BR /&gt;points(index) = v(i)&lt;BR /&gt;points(index + 1) = v(i + 1)&lt;BR /&gt;points(index + 2) = 0&lt;BR /&gt;&lt;BR /&gt;index = index + 3&lt;BR /&gt;Next&lt;BR /&gt;points(index) = points(0)&lt;BR /&gt;points(index + 1) = points(1)&lt;BR /&gt;points(index + 2) = 0&lt;/P&gt;&lt;P&gt;savepoints = points&lt;/P&gt;&lt;P&gt;End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On Error Resume Next&lt;BR /&gt;Set selectionSet = MyDWG.SelectionSets.Add("MySelectionSet")&lt;BR /&gt;If Err Then&lt;BR /&gt;Err.Clear&lt;BR /&gt;Else&lt;BR /&gt;selectionSet.Delete&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;'Set selectionSet = MyDWG.SelectionSets.Add("TEST_SSET2")&lt;BR /&gt;Set selectionSet = MyDWG.SelectionSets.Add("MySelectionSet")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Dim mode As Integer&lt;BR /&gt;Dim j As Integer&lt;BR /&gt;j = ((UBound(v) + 1) / 2 + 1) * 3 - 1&lt;BR /&gt;ReDim Preserve pointsArray(0 To j) As Double&lt;BR /&gt;'ReDim Roompoints(0 To j) As Double&lt;/P&gt;&lt;P&gt;mode = acSelectionSetCrossingPolygon&lt;BR /&gt;pointsArray = savepoints&lt;BR /&gt;'For i = 0 To j&lt;BR /&gt;'Roompoints(i) = pointsArray(i)&lt;BR /&gt;'Next i&lt;/P&gt;&lt;P&gt;pointsArray = points&lt;/P&gt;&lt;P&gt;selectionSet.SelectByPolygon mode, pointsArray&lt;BR /&gt;'selectionSet.SelectByPolygon mode, Roompoints&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;MsgBox Err.Description&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 18:06:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11807793#M1776</guid>
      <dc:creator>jalal.mousa</dc:creator>
      <dc:date>2023-03-08T18:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: SelectByPolygon Method (ActiveX) Selectselection set , select all region (objects inside polyline points)</title>
      <link>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11807926#M1777</link>
      <description>&lt;P&gt;First, please use the &amp;lt;/&amp;gt; button to paste your code into a code window. It's hard to read as plain text and looses it formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't add a selectionset if it already exists. A method or function should only do one thing. If you try to do too many tasks in the same method inline with the rest of your code, it will be hard to troubleshoot and you will waste effort duplicating code. If you don't develop good programming habits, you will continuously run into error like this. For example, you will often need to select objects, so create a function that does only that and reuse it. Your use of On Error Resume Next is masking the error that the selectionset already exists. Since you get an error, your Set statement fails. You don't need to delete the ss, a good function would just return the existing ss if it already exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Public Function AddSelectionSet(SetName As String) As AcadSelectionSet
' This routine does the error trapping neccessary for when you want to create a
' selectin set. It takes the proposed name and either adds it to the selectionsets
' collection or sets it.
    On Error Resume Next
    Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName)
    If Err.Number &amp;lt;&amp;gt; 0 Then
        Set AddSelectionSet = ThisDrawing.SelectionSets.Item(SetName)
        AddSelectionSet.Clear
    End If
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same problem with trying to get an instance of acad. Keep it in a separate function. When you use On Error Resume Next, it remains in effect until you use On Error GoTo 0. If you don't, you'll never know where other errors are coming from. That's why it's beneficial to keep your code modular, for troubleshooting, you limit errors to the scope of one method.&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Public Function GetAcad(Optional ver As String) As AcadApplication
    ' support multiple acad versions.
    'Sample ver for AutoCAD 2023 ' ".24.2"
    On Error Resume Next
    Dim acApp As AcadApplication
    Dim clsid As String
    clsid = "AutoCAD.Application"
    If Not ver = "" Then
        clsid = clsid &amp;amp; ver
    End If
    Set acApp = GetObject(, clsid)
    If acApp Is Nothing Then
        Set acApp = CreateObject(clsid)
    End If
    Set GetAcad = acApp
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 18:38:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/selectbypolygon-method-activex-selectselection-set-select-all/m-p/11807926#M1777</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-03-08T18:38:10Z</dc:date>
    </item>
  </channel>
</rss>

