<?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: Highlighting or selecting elements from vba code in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594756#M3117</link>
    <description>&lt;P&gt;Since the command line can interpret lisp, you have to get the lisp version of the handle and format it as lisp and pass that as an argument to the command being entered with SendCommand. I wrote a function to assist with that. Some commands will accept a selectionset as the argument. You'll have to try it with the arch command you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Public Function Ent2lspEnt(entObj As AcadEntity) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String
    
    entHandle = entObj.Handle
    Ent2lspEnt = "(handent " &amp;amp; Chr(34) &amp;amp; entHandle &amp;amp; Chr(34) &amp;amp; ")"
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 20:11:46 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2021-09-02T20:11:46Z</dc:date>
    <item>
      <title>Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10581666#M3113</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with AutoCad 2022 and with Excel VBA. In my code, I read in a Excel Worksheet the info that I need from the drawing including the Handle of the Entities I am interested on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next step, to verify some Acad Drawing info based on Excel calculations. For this, I pick the Entities Handle ID on Excel and it highlights the Entity on Acad. Some times Entities highlighting doesn't do enough contrast to differentiate the element of my interest between all the other objects and it is hard to see it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I think It would be better if the entity I need to verify get selected, as it is made in Acad environment with the mouse. Unfortunately, the practical way to verify the info is accessing by the Handle ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have looked for alternatives in Internet and found something regarding with SelectionSets, but result was not different of just highlight the entity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion to select (as with the mouse) or to improve the colors or highlighting characteristics of the entities?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attach some pics how is my highlighted objects showing up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub dfSelHnd()&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; actldwg &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; AcadDocument
&lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; tAr(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;) &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; AcadEntity &lt;SPAN class="hljs-comment"&gt;'Add items to selectionset must be done with arrays&lt;/SPAN&gt;

&lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; rng &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; Range
&lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; txt &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; &lt;SPAN class="hljs-type"&gt;String&lt;/SPAN&gt;

&lt;SPAN class="hljs-comment"&gt;''---&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;''---&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;''---&lt;/SPAN&gt;

&lt;SPAN class="hljs-keyword"&gt;Set&lt;/SPAN&gt; rng = Selection
&lt;SPAN class="hljs-keyword"&gt;Set&lt;/SPAN&gt; actldwg = AutoCAD.Application.ActiveDocument

txt = rng.Value &lt;SPAN class="hljs-comment"&gt;'' txt is the HandleID&lt;/SPAN&gt;

&lt;SPAN class="hljs-keyword"&gt;Set&lt;/SPAN&gt; tAr(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;) = actldwg.HandleToObject(txt)

&lt;SPAN class="hljs-keyword"&gt;Call&lt;/SPAN&gt; zoomit(actldwg, tAr(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;))
tAr(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;).Highlight (&lt;SPAN class="hljs-literal"&gt;True&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;End Sub'''&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 21:29:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10581666#M3113</guid>
      <dc:creator>ofcarvajall</dc:creator>
      <dc:date>2021-08-28T21:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10583053#M3114</link>
      <description>&lt;P&gt;If I understand your question correctly, what you want is provide user with visual hint of which entity (or entities) is/are the target(s) of the code execution while the code execution is waiting for user interaction (if the code execution does not need to wait for user interaction, then there is no point to provide visual hint to user, right?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With VBA/COM API, your option is quite limited. Basically you just use Entity.Highlight(True/False) method. As for SelectionSet, it is just a entity container and is different from the action when user manually select entities in AutoCAD editor. Once your code creates a SelectionSet, the look of the "selected" (by code) entities do not change (do not get highlighted), unless you call HIghlight() on each entity in the SelectionSet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are not satisfied with the visual effect of Highlight() method, you might consider to TEMPORARILY change the entity's color, lineweight (you have to enable AutoCAD to show lineweight, of course) to make it more eye-catching. Or you can even drawing something temporarily, like the entity's bounding box, a circle around it... Well, you have to make sure to reverse the temporary change back when the code execution no longer need to prompt user for the target entities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With AutoCAD .NET API, there are more options you could choose without having to change entity's properties (color, lineweight) or draw temporary entities. You can overrule the regular highlight to whatever visual effects you like; or you could also use DrawableOverrule, TransientGraphics...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 20:31:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10583053#M3114</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-08-29T20:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10583678#M3115</link>
      <description>&lt;P&gt;Hello Norman,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help and your reply. As you mention, my intention is to give the user a visual hint to know which entity is working with and to allow user to complete in excel the info that it is needed. The main code goes entity by entity, highlighting each one and giving time for the user interaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using some of the solutions you indicate, I am drawing a circle. Other option I found was to change Selection effect color (right click on Acad Screen, selection tab, selection effect color). It doesn't work always, depending on the entity original color but made the interaction with the user easier.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand from your answer that form VBA is not possible to select (as it is possible to do with the mouse over an entity, picking it on, an getting blue highlighting and showing up blue squares). Is there a way to "select" the entity as it is possible with the mouse?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am pretty new in Acad Vba, I will also try with&amp;nbsp;&lt;SPAN&gt;AutoCAD .NET API.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Many thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Oscar&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 05:37:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10583678#M3115</guid>
      <dc:creator>ofcarvajall</dc:creator>
      <dc:date>2021-08-30T05:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594368#M3116</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I wanted to ask a similar question, so I'll put it here.&lt;/P&gt;&lt;P&gt;Is it somehow possible to select objects through VBA so that one can then apply a command via the command line? It is about the command shrinkwrap from AutoCAD architecture, which, as far as I know, does not exist as a VBA command. But I only want to select objects with different parameters and layer names. I get that also in a SelectionSet, but as you wrote above, it is a different one than in the AutoCAD GUI and cannot be selected from there. Does anyone know a solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With kind regards,&lt;/P&gt;&lt;P&gt;Philipp&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 17:27:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594368#M3116</guid>
      <dc:creator>reuter.philipp</dc:creator>
      <dc:date>2021-09-02T17:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594756#M3117</link>
      <description>&lt;P&gt;Since the command line can interpret lisp, you have to get the lisp version of the handle and format it as lisp and pass that as an argument to the command being entered with SendCommand. I wrote a function to assist with that. Some commands will accept a selectionset as the argument. You'll have to try it with the arch command you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Public Function Ent2lspEnt(entObj As AcadEntity) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String
    
    entHandle = entObj.Handle
    Ent2lspEnt = "(handent " &amp;amp; Chr(34) &amp;amp; entHandle &amp;amp; Chr(34) &amp;amp; ")"
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 20:11:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594756#M3117</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2021-09-02T20:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594816#M3118</link>
      <description>&lt;P&gt;Thanks, I will test that, but also had another idea because I found a similar question in the forum. I wanted to try to create a named group with it, which should then be selectable from the command line. But the code is not tested yet.&lt;/P&gt;&lt;P&gt;I just saw that you had commented there too &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/vba/selecting-objects-on-the-model-from-selectionset-created-in-vba/td-p/6723450" target="_blank"&gt;https://forums.autodesk.com/t5/vba/selecting-objects-on-the-model-from-selectionset-created-in-vba/td-p/6723450&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Public Sub SSToGroup(SelectionSetName as String, ss As AcadSelectionSet)
    'Set ss = ThisDrawing.SelectionSets.Add(SelectionSetName)
    ss.Select acSelectionSetAll
    ss.Delete
    ThisDrawing.SendCommand "_SELECT" &amp;amp; vbCr &amp;amp; "_PREVIOUS" &amp;amp; vbCr
    ThisDrawing.SendCommand "-GROUP" &amp;amp; vbCr &amp;amp; "Test" &amp;amp; vbCr
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With kind regards,&lt;/P&gt;&lt;P&gt;Philipp&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 20:40:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10594816#M3118</guid>
      <dc:creator>reuter.philipp</dc:creator>
      <dc:date>2021-09-02T20:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10604827#M3119</link>
      <description>&lt;P&gt;You can select entities in VBA by select group.&lt;/P&gt;&lt;PRE&gt; ThisDrawing.SendCommand (&lt;SPAN class="hljs-string"&gt;"_SELECT"&lt;/SPAN&gt; + vbCr + &lt;SPAN class="hljs-string"&gt;"G"&lt;/SPAN&gt; + vbCr + GroupName + vbCr + vbCr)&lt;/PRE&gt;&lt;P&gt;So first You need to create selectionset, then make a group from selectionset. Full sample would be: &lt;A href="https://www.jbbatteryrussia.com/" target="_self"&gt;&lt;FONT color="#fef3e3"&gt;Jbbattery Russia&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-keyword"&gt;Public&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;Sub&lt;/SPAN&gt; Test()
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; ssh &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; AcadSelectionSet
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; Ftyp(&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;) &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; &lt;SPAN class="hljs-type"&gt;Integer&lt;/SPAN&gt;
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; Fdat(&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;) &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; Variant
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; BlockName &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; &lt;SPAN class="hljs-type"&gt;String&lt;/SPAN&gt;
    BlockName = &lt;SPAN class="hljs-string"&gt;"A-1"&lt;/SPAN&gt;
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; F1, F2 &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; Variant
    Ftyp(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;) = &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;: Fdat(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;) = &lt;SPAN class="hljs-string"&gt;"Insert"&lt;/SPAN&gt;
    Ftyp(&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;) = &lt;SPAN class="hljs-number"&gt;2&lt;/SPAN&gt;: Fdat(&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;) = BlockName
    &lt;SPAN class="hljs-keyword"&gt;Set&lt;/SPAN&gt; sstest = ThisDrawing.SelectionSets.Add(&lt;SPAN class="hljs-string"&gt;"sstest"&lt;/SPAN&gt;)
    F1 = Ftyp
    F2 = Fdat
    sstest.&lt;SPAN class="hljs-keyword"&gt;Select&lt;/SPAN&gt; acSelectionSetAll, , , Ftyp, Fdat
     
    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; GroupName &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; &lt;SPAN class="hljs-type"&gt;String&lt;/SPAN&gt;
    GroupName = &lt;SPAN class="hljs-string"&gt;"sstest"&lt;/SPAN&gt;

    &lt;SPAN class="hljs-keyword"&gt;Dim&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;group&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;As&lt;/SPAN&gt; AcadGroup
    &lt;SPAN class="hljs-keyword"&gt;Set&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;group&lt;/SPAN&gt; = ThisDrawing.Groups.Add(GroupName)
    &lt;SPAN class="hljs-keyword"&gt;For&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;Each&lt;/SPAN&gt; Item &lt;SPAN class="hljs-keyword"&gt;In&lt;/SPAN&gt; sstest
        &lt;SPAN class="hljs-keyword"&gt;group&lt;/SPAN&gt;.AppendItems (Item)
    &lt;SPAN class="hljs-keyword"&gt;Next&lt;/SPAN&gt;
    sstest.Delete
    ThisDrawing.SendCommand (&lt;SPAN class="hljs-string"&gt;"_SELECT"&lt;/SPAN&gt; + vbCr + &lt;SPAN class="hljs-string"&gt;"G"&lt;/SPAN&gt; + vbCr + GroupName + vbCr + vbCr)
    &lt;SPAN class="hljs-keyword"&gt;group&lt;/SPAN&gt;.Delete
&lt;SPAN class="hljs-keyword"&gt;End&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;Sub&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;This sample code mark selected blocks (by name). Now You should change the way of selection. But it's not the question, so I hope You will handle it easy.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 08:50:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10604827#M3119</guid>
      <dc:creator>iamzain16</dc:creator>
      <dc:date>2021-09-07T08:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Highlighting or selecting elements from vba code</title>
      <link>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10605642#M3120</link>
      <description>&lt;P&gt;I wouldn't go about creating a GROUP object just to be able to select entities, unless you are already using groups.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 14:18:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/highlighting-or-selecting-elements-from-vba-code/m-p/10605642#M3120</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2021-09-07T14:18:49Z</dc:date>
    </item>
  </channel>
</rss>

