<?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: Get entity and selection sets in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10486304#M3228</link>
    <description>&lt;P&gt;I am not sure and you did not say why you need a SelectionSet now that you can pick entities.&amp;nbsp; With that said, you can add entities, which is identified by your code, such as asking user to pick with GetEntity() method, to SelectionSet by calling AcadSelectionSet.AddItems() method (you cannot assign entity to SelectionSet's element, as you already know).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your process is likely expect user to pick multiple entities, you probably let user to keep picking until it is done and then add all the picked entities (saved in an entity array during picking) into the SelectionSet at the end at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, the code you showed is really bad (sorry to say that :-() - using label to let code execution to jump around is already bad enough practice, yet you have code execution jumps out of Do...Loop and then going into the loop again? You'd better re-structure the code again and do not use label to turn execution flow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jul 2021 21:31:32 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2021-07-21T21:31:32Z</dc:date>
    <item>
      <title>Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10485975#M3226</link>
      <description>&lt;P&gt;Hello world and Mr. Yuan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to use Getentity method to create a selection set.&lt;/P&gt;&lt;P&gt;I have put the Getentity method in some sort of loop which will take entities till the user clicks on a command button in the userform (vbmodeless) or presses escape which will go to another userform.&lt;/P&gt;&lt;P&gt;my problem is, I can see the picked item in getentity but my code wont assign it to the selection set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim keepsset as acadselectionset&lt;/P&gt;&lt;P&gt;dim entity as acadentity&lt;/P&gt;&lt;P&gt;i = 0&lt;/P&gt;&lt;P&gt;GetEntityObject:&lt;BR /&gt;&lt;BR /&gt;On Error Resume Next&lt;BR /&gt;ThisDrawing.Utility.GetEntity Entity, bp, vbNewLine &amp;amp; "Select Items to keep in Plan"&lt;BR /&gt;&lt;BR /&gt;Do While Entity Is Nothing&lt;BR /&gt;If CheckKey(VK_ESCAPE) = True Then&lt;/P&gt;&lt;P&gt;me.hide&lt;/P&gt;&lt;P&gt;initialform.show&lt;BR /&gt;Else&lt;BR /&gt;MsgBox "Emtpy area selected" &amp;amp; vbNewLine &amp;amp; "Select an Object or Press ESC to go to previous Form"&lt;BR /&gt;GoTo GetEntityObject&lt;BR /&gt;End If&lt;BR /&gt;Loop&lt;BR /&gt;&lt;BR /&gt;Set KeepSSet(i) = Entity&lt;BR /&gt;Entity.Highlight True&lt;/P&gt;&lt;P&gt;i = i + 1&lt;BR /&gt;GoTo GetEntityObject&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the reason why Im using getentity instead of KeepSSet.SelectOnScreen is so I can use the prompt in getentity.&lt;/P&gt;&lt;P&gt;any ideas if i can do the same if i use .SelectOnScreen?&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 19:31:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10485975#M3226</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2021-07-21T19:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10486229#M3227</link>
      <description>&lt;P&gt;When i use selection set, i always do in this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sub SSTest()

Dim SS As AcadSelectionSet: Set SS = ThisDrawing.SelectionSets.ADD("SS00"): SS.SelectOnScreen

Dim AcadObj As AcadEntity

For Each AcadObj In SS

    Debug.Print AcadObj.ObjectName

Next AcadObj

SS.Delete

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this code help u?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 21:03:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10486229#M3227</guid>
      <dc:creator>seabrahenrique</dc:creator>
      <dc:date>2021-07-21T21:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10486304#M3228</link>
      <description>&lt;P&gt;I am not sure and you did not say why you need a SelectionSet now that you can pick entities.&amp;nbsp; With that said, you can add entities, which is identified by your code, such as asking user to pick with GetEntity() method, to SelectionSet by calling AcadSelectionSet.AddItems() method (you cannot assign entity to SelectionSet's element, as you already know).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your process is likely expect user to pick multiple entities, you probably let user to keep picking until it is done and then add all the picked entities (saved in an entity array during picking) into the SelectionSet at the end at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, the code you showed is really bad (sorry to say that :-() - using label to let code execution to jump around is already bad enough practice, yet you have code execution jumps out of Do...Loop and then going into the loop again? You'd better re-structure the code again and do not use label to turn execution flow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 21:31:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10486304#M3228</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-07-21T21:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488383#M3229</link>
      <description>&lt;P&gt;Dear Mr. Yuan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the tip about labels and loops.&lt;/P&gt;&lt;P&gt;the main goal is Deleting a SelectionSet which some elements of it have to be removed out of the SelectionSet before being deleted.&lt;/P&gt;&lt;P&gt;when the userform is activated, the programs asks the user to pick the Items that should not be removed.&lt;/P&gt;&lt;P&gt;then when he/she are done, Confrim Delete button is pressed and it deletes the Items in the SelectionSet.&lt;/P&gt;&lt;P&gt;so I have to define a public SelectionSet to store the Items which has to be kept in it because I define a public EntityArray.&lt;/P&gt;&lt;P&gt;then I have to take set each element of that SelectionSet to an array and remove them From the main SelectionSet so I can delete the main SelectionSet&lt;/P&gt;&lt;P&gt;By the way the reason why Im Avoiding SelectionSet2.SelectOnScreen is that I want to have a tooltip on the mouse prompting "Pick Items you want to keep" which I cant while using SelectOnScreen method.&lt;/P&gt;&lt;P&gt;so this is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public SelectionSet2 As AcadSelectionSet&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Sub userform_activate()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim entity As AcadEntity&lt;BR /&gt;Dim EntityArray() As AcadEntity&lt;BR /&gt;Dim i As Integer&lt;BR /&gt;i = 0&lt;BR /&gt;Dim condition As Boolean&lt;BR /&gt;condition = True&lt;BR /&gt;&lt;BR /&gt;Do While condition&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ThisDrawing.Utility.GetEntity entity, bp, "pick an item"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;condition = False&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ReDim EntityArray(i)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Set EntityArray(i) = entity&lt;BR /&gt;&amp;nbsp; &amp;nbsp;i = i + 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp;If Not entity Is Nothing Then condition = True&lt;BR /&gt;Loop&lt;BR /&gt;&lt;BR /&gt;For i = 0 To UBound(EntityArray)&lt;BR /&gt;Set SelectionSet2(i) = EntityArray(i)&lt;BR /&gt;Next&lt;BR /&gt;&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;Sub DeleteItems_click()&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Dim SelectionSet1 As AcadSelectionSet&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Set SelectionSet1 = ThisDrawing.SelectionSets.Add("set1")&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Dim block_filterdata(0) As Integer&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Dim block_filtertype(0) As Variant&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;block_filterdata(0) = 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp;block_filtertype(0) = "xxx"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;SelectionSet1.Select acSelectionSetAll, , , block_filterdata, block_filtertype&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;For i = 1 To SelectionSet2.Count - 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; KeepArray(i) = SelectionSet2(i)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Next&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;SelectionSet1.RemoveItems KeepArray&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Dim elem As AcadEntity&lt;BR /&gt;&amp;nbsp; &amp;nbsp;For Each elem In SelectionSet1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; elem.Delete&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Next&lt;/P&gt;&lt;P&gt;End Sub&lt;/P&gt;&lt;P&gt;can you give me a hand in the code Sir?&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 15:52:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488383#M3229</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2021-07-22T15:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488390#M3230</link>
      <description>&lt;P&gt;Hello Sir. Not really because I already know that my SelectionSet is empty and its not getting the entities which its suppose to.&lt;/P&gt;&lt;P&gt;but thanks anyways&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 15:54:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488390#M3230</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2021-07-22T15:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488444#M3231</link>
      <description>&lt;P&gt;Let's critique the first portion of your code (in blue)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;'' I assume this selectionset is created prior to the code below being executed&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Public SelectionSet2 As AcadSelectionSet&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sub userform_activate()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim entity As AcadEntity&lt;BR /&gt;Dim EntityArray() As AcadEntity&lt;BR /&gt;Dim i As Integer&lt;BR /&gt;i = 0&lt;BR /&gt;Dim condition As Boolean&lt;BR /&gt;condition = True&lt;BR /&gt;&lt;BR /&gt;Do While condition&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ThisDrawing.Utility.GetEntity entity, bp, "pick an item"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;condition = False&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#0000FF"&gt;'' You missed keyword "Preserve", therefore, each "ReDim" makes previous picked entity lost&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ReDim &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;Preserve&lt;/FONT&gt;&lt;/STRONG&gt; EntityArray(i)&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Set EntityArray(i) = entity&lt;BR /&gt;&amp;nbsp; &amp;nbsp;i = i + 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp;If Not entity Is Nothing Then condition = True&lt;BR /&gt;Loop&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;'' You cannot set each element in a SelectionSet&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;'' Instead you use AcadSelectionSet.AddItems&lt;/FONT&gt;&lt;BR /&gt;''For i = 0 To UBound(EntityArray)&lt;BR /&gt;''Set SelectionSet2(i) = EntityArray(i)&lt;BR /&gt;''Next&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;SelectionSet2.AddItems EntityArray&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 16:16:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10488444#M3231</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-07-22T16:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Get entity and selection sets</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10491593#M3232</link>
      <description>&lt;P&gt;I Fixed it with a little bit of change.&lt;/P&gt;&lt;P&gt;Thank you very much Sir.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 19:00:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-entity-and-selection-sets/m-p/10491593#M3232</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2021-07-23T19:00:22Z</dc:date>
    </item>
  </channel>
</rss>

