select all items in the selectionset

select all items in the selectionset

flowerpapa
Enthusiast Enthusiast
9,228 Views
28 Replies
Message 1 of 29

select all items in the selectionset

flowerpapa
Enthusiast
Enthusiast

I have initialized a AcadSelectionset, and have added few items in the selectionset.
Now i want to select all items present in the particular selectionset only

0 Likes
Accepted solutions (2)
9,229 Views
28 Replies
Replies (28)
Message 21 of 29

Ed__Jobe
Mentor
Mentor

As the last link I gave you shows, that in .NET, the regapp has to be added to the reagapp table first. This link shows you how to do it in VBA,

 

As far as using forms goes, you don't need a separate exe to do that. Your plugin could autorun and open a form upon launching acad. Then you could use the .NET api instead of the COM/ActiveX api. If you don't want to rely on the user having acad installed, you could use Platform Services.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 22 of 29

norman.yuan
Mentor
Mentor

While I am not a fan of using EXE to automate AutoCAD in most cases, I get your point of why doing things this way. In this case, as you emphasized, of not want/require user to directly interact with AutoCAD, then the all discussions of this thread are useless for you. 

 

As I pointed out, the OP wanted to run the VBA code, and when the code execution is done, some entities would be left in AutoCAD editor highlighted with grips, as if they were selected by user manually. Then, use might want to execute a "pick-first" enabled command. That is, the code is doing "manual selection" on behalf the user.

 

In your code, you only need to create a AcadSelectionSet with code and select targeted entities and the code continues. There is no need to make the entities in a AcadSelectionSet being visible to user. Maybe, you need to understand the difference between a selection set selected by user manually and AcadSelectionSet created by VBA code. While you may have learned how to attach XData to entity by now, it is completely useless/pointless to use it in this particular case.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 23 of 29

george1985
Collaborator
Collaborator

Thank you both of you for the replies @norman.yuan  and @Ed__Jobe 

Norman, the reason why I am trying to use your code, is so that I can run the "XEDGES" command on the selected 3D solid. I would like to get all the edge curves of a solid.
Is there any other way, the "XEDGES" command can be run, without having the 3D solid selected, as if user selected it?

0 Likes
Message 24 of 29

leandrocg
Explorer
Explorer
Thanks!!!!!
0 Likes
Message 25 of 29

george1985
Collaborator
Collaborator

The line I am struggling right now is this one:

ThisDrawing.ActiveSelectionSet.Select acSelectionSetAll, , , groupCode, dataCod

This line actually works. However, if one of the previously selected autocad objects does not exist anymore (for example I used an "EXPLODE" command to obtain regions from a 3Dsolid), then this line is raising an error:

              "Calling method AddItems of interface IAcadSelectionSet failed"


There are a number of Lisp topics ([1], [2]) about this same error, and all of them are mentioned that I have to delete all selection sets, after creation of a selection set (I assume that's the upper line).
But even when I iterate through ThisDrawing.SelectionSets and call "Delete()" method on all of the selSets - still the upper error appears again.


Does anyone have any suggestion how I can avoid the upper error message appearing? I am quite desperate at the moment. @norman.yuan I apologize for disturbing you, after you have already provided us the solution for selecting objects.

0 Likes
Message 26 of 29

Ed__Jobe
Mentor
Mentor

Please read again, Norman's explanation in post 8. If you explode objects that were in the selection set, then the ActiveSelectionset is not going to get updated until you execute a new selection. The selection set contains a list of ObjectID's. If you delete an entity, the list of ObjectID's in the selection set will no longer be valid. Thus, when you try to refer to the selection set again, you get an error. Because of this limitation with the ActiveSelectionset object, I tend to use a regular selection set that you can keep updated. For working with the SendCommand method, you can then pass a SelectionSet to a command using the lisp (handent) function. It take a handle and converts it to a lisp entity that the SendCommand can use. All Entity objects have a Handle property. I wrote the VBA function below, which shows how to process the handle as a string that you can pass to the SendCommand method. For usage, see this post.


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 " & Chr(34) & entHandle & Chr(34) & ")"
End Function

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 27 of 29

george1985
Collaborator
Collaborator

Dear @Ed__Jobe 
Thank you very much for your help, patience and shared knowledge.

I still don't understand that post number 8 from Norman, nor explanation above.


But nevertheless I used your above solution which worked perfectly!!!
You even taught me something new additionally:

- Lisp possesses more ActiveX functionalities than VBA

- I can run Lisp commands by just calling the regular ThisDrawing.SendCommand in VBA!

I don't know how to thank you.

0 Likes
Message 28 of 29

Ed__Jobe
Mentor
Mentor

1. No, lisp doesn't possess more ActiveX than VBA. It's the same underlying structure for both. I just find using ActiveX easier in vba, mainly because of vba's IDE.

2. Yes, you can type lisp at the command prompt.

 

Let's see if I can explain the selectionset problem simpler. Let's say a selectionset contains the ObjectID's (1,2,3,4,5). You explode object 3, which deletes that ID from the database. However, the ss still says 1-5. If you try to access the ss, you will get an error because 3 is gone from the set. You need to run the ss.Select method again to refresh the list of ObjectID'. Now you can access the set again without getting an error. The problem is similar to iterating a collection. Take a look at the code below.

For Each layerObject in ThisDrawing.Layers
   If layerOjbect.Linetype = acContinuous then layerObject.Delete
Next

If you delete an object in a collection, it changes the index to the collection. You may get unpredictable results with the code above, because each time the For..Each does an iteration, you are changing the list of items in the Layers collection. The list is not the same as when you started the loop.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 29 of 29

george1985
Collaborator
Collaborator

Dear @Ed__Jobe ,
My apologies for the late reply.
Thank you very much for all your help and patience once again.

What would this AutoCAD community do without you!