AcadSelectionSet.Select not fit for purpose?

AcadSelectionSet.Select not fit for purpose?

Anonymous
Not applicable
2,075 Views
4 Replies
Message 1 of 5

AcadSelectionSet.Select not fit for purpose?

Anonymous
Not applicable

Hello everybody. First message on the forums but been reading you for ages :).

I'm struggling to understand what the AcadSelectionSet.Select method is actually for. I thought it would eventually allow me to highlight objects the same way the Quick Select tool does and then modify them to suit my needs. That doesn't seem to be the case and I'm wondering what I'm doing wrong here.

 

My goal is to select determined (dynamic) blocks in a specific layer to subsequently explode them by means of the Burst command in order to not mess the blocks up. To get familiar with the AcadSelectionSet object and its methods, I started playing around with just the selection of circles in my drawing, first, and then layers. I initially used the AcadSelectionSet.SelectOnScreen method and it went relatively well except that it's not like the Quick Select tool and I don't see the use. On top of that, it was not picking up the blocks. No matter how many times I've tried. I've tried removing blanks in the blocks names, shortening, redefining them... Without success. Which has driven me nuts. Hint: By using the oldschool Filters, they would not pick up some of my blocks either (?!).

 

Anyways, given that my goal is to do everything from the code without having the user to interact with the space model at this stage, I opted for AcadSelectionSet.Select thinking it was magically going to fix the problems I've just mentioned with the blocks. And that's when things got even worse: running the code had no effect at all, it was as if nothing had been selected. Now, I couldn't even select the circles nor the objects in the layers. Next, you can see my code for the circles that doesn't work at all:

 

Sub FiltrarCírculos()

Dim MiFiltro As AcadSelectionSet
Dim TipodeFiltro(0) As Integer
Dim DatodeFiltro(0) As Variant
Dim i As Integer
Set MiFiltro = ThisDrawing.SelectionSets.Add("MisBloques")
TipodeFiltro(0) = 0
DatodeFiltro(0) = "Circle"
MiFiltro.Select acSelectionSetAll, , , TipodeFiltro, DatodeFiltro
' MiFiltro.SelectOnScreen TipodeFiltro, DatodeFiltro
' MiFiltro.Delete
End Sub

 

I've commented out the last two lines because, on the one hand, I've been trying switching between the Select and the SelectOnScreen methods to see if that could do the trick, on the other hand, I thought that deleting the SelectionSet could cancel it and thus no actual selection would be visible. Again, it didn't work.

 

Sorry for the long explanation, I wanted to be as much thorough as possible. Could you please shed light on what's wrong with the Select method and what is the AcadSelectionSet for?

 

Thank you. 

0 Likes
Accepted solutions (2)
2,076 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Do not confuse the programmatical selecting with manual selecting in AutoCAD editor, or AutoCAD's QuickSelect command. The purpose of AcadSelectionSet.Select()/SelectXXXX() methods are meant for your VBA code to identify some AcadEntity objects for further process/action in your code. It does not automatically provide visual hint (highlight) to user (because when your code runs, user may or may not need to see what entities being processed), except SelectOnScreen(), which does highlight selected entities (because it allows manual selecting, visual hint is necessary!).

 

So, except for calling SelectOnScreen, if in the VBA code execution you do need user to see which objects are selected, you need to write code to highlight the entities in the selectionset.

 

To let yourself know if there is actually entities selected in the selectionset, you can add some DEBUG code like:

 

Sub FiltrarCírculos()

  Dim MiFiltro As AcadSelectionSet
  Dim TipodeFiltro(0) As Integer
  Dim DatodeFiltro(0) As Variant
  Dim i As Integer
  Set MiFiltro = ThisDrawing.SelectionSets.Add("MisBloques")
  TipodeFiltro(0) = 0
  DatodeFiltro(0) = "Circle"
  MiFiltro.Select acSelectionSetAll, , , TipodeFiltro, DatodeFiltro
  MsgBox "Selected entity count: " & MiFiltro.Count

  '' If you need to highlight selected entities

  Dim ent As AcadEntity

  For Each ent In MiFiltro

    ent.Highlight True

  Next

  MsgBox "See seelcted entities"
  MiFiltro.Delete
End Sub

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for replying. I understand it much better now. I can see the Circle highlighted, not showing any grips though, thus not allowing for edition of the highlighted items directly on the screen (say, moving them to another layer) but just from the code as you said. 

 

If I was to design a macro capable of selecting some shapes (arcs and lines, for instance) with the aim to leave the user to edit them in the model space, that wouldn't be possible then, right? Once I had the Circle selected it 's just as you said, I couldn't do anything from the model space (e.g. change its colour). Is there a way to highlight everything by using the macro to then leave the user to edit the selection from the ribbon?

 

As for the dynamic blocks issue, I'm going to open another thread because VBA doesn't recognize some block names (0 count) whereas it does it partially for others (its counting 3 instances of one particular dynamic block instead of the actual 5).   

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

If the purpose of running your code is to programmatically identify some entities, and then make them "selected" as if being selected by user manually (or as if you run the command "QuickSelect"), so user can run other command on these selected entities, then yes, you can do it. The trick is, after you created the AcadSelectionSet and have it select target entities with code, simply add one more line of code to send the entities to AutoCAD's built-in selection set "Previous" with SendCommand(). Following code shows how to do it:

 

Option Explicit

Public Sub SelectSomething()
Dim ss As AcadSelectionSet Set ss = BuildSelectionSet If ss.Count > 0 Then ThisDrawing.SendCommand "SELECT" & vbCr & "P" & vbCr & vbCr End If End Sub Private Function BuildSelectionSet() As AcadSelectionSet Dim ss As AcadSelectionSet On Error Resume Next Set ss = ThisDrawing.SelectionSets("MySet") If ss Is Nothing Then Set ss = ThisDrawing.SelectionSets.Add("MySet") Else ss.Clear End If '' Select all or you can add whatever filter you want ss.Select acSelectionSetAll MsgBox "Selected block count: " & ss.Count Set BuildSelectionSet = ss End Function

After running this macro ("SelectSomething"), you should be able to see all entities are selected as if being selected manually. With proper selecting filter applied, or some code, you can easily get results similar to running "QuickSelect" command.

 

HTH

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

Anonymous
Not applicable

Brilliant. Thank you very very much. The selection tools is something that I completely disregard on my daily use of Autocad and there you go, they are of use! Hopefully, the VBA study will help me get a better understanding of AutoCad (I thought I knew it all, lol).

0 Likes