I am trying to cycle thru and select each item and then perform actions on them.
What I have right now is..
For Each ObjEnt In ThisDrawing.ModelSpace
If TypeOf ObjEnt Is AcadMText Then
*Here I need to select the current object in Autocad*
Any help would be greatly appreciated.
Solved! Go to Solution.
Solved by Markintx. Go to Solution.
Hi,
I guess the question is not clear and that might be the reason for no response.
You ask for:
>> I need to select the current object
And now what is unclear (at least for me):
You have a current object, so what is to select? You already have it, otherwise it would not be currently selected.
Describe more from what you try to accomplish, that will make it more clear for us and so the answers will arrive (hopefully).
- alfred -
I want to select the current object in the onscreen in autocad,or maybe I want to make a selection set out of the current object would be a better way to put it.
My goal is to take each of those objects and use SendCommand to move or modify each one.
I hope this clarifies my question more.
Thanks again.
Hi,
with VBA and your wish to run that with SendCommand (which I would try to avoid as often as possible) you can use the handle and LISP to make an object selected.
The LISP statement therefor is:
(sssetfirst (setq SELSET (ssadd (handent "287"))) SELSET)
That makes the object with handle &h287 selected/gripped.
(whereas "287" is a handle (hex value of a handle), you should take your handle from your routine.)
If you want to use move with that single object you can start
_MOVE
(handent "287")
0,0,0,
1,1,1
...also with SendCommand.
But take care, SendCommand is easy to use in some cases, but generates a lot of conflicts as you don't get feedback (e.g if the user cancels within the command).
Good luck, - alfred -
Do you know how to select the object in my example from VBA (I dont use LISP)
Answering that would be a great help.
Hi,
with VBA I don't know a way to get a object selected/gripped.
But you can use SendCommand to send the LISP statement 😉
- alfred -
I was able to achieve the desired results using the handet command you suggested
Here is what is I was able to get to work.
For Each ObjEnt In ThisDrawing.ModelSpace
If TypeOf ObjEnt Is AcadMText Then
ObHandle = ObjEnt.Handle
lisp = "(handent " & Chr(34) & ObHandle & Chr(34) & ") "
ThisDrawing.SendCommand ("select ")
ThisDrawing.SendCommand (lisp)
Thanks again for the help.
I selected my repost as the answer to make it easier for somone to find exactly what worked.
Thanks to Alfred.NESWADBA for pushing me in the right direction.
I also want to do the same action. I tried to make a code based on your solution but failed.
can you please post your whole code.
thanx
Here is a simplified version that works.
Open a blank drawing and create 3 or 4 pieces of Mtext
then Step through this code with F8 instead of just running the code and you can watch each step.
It will select each object and then erase it, then select the next one, and erase it.
Sub SelectVBA()
Dim ObjEnt As AcadEntity
Dim ObHandle As Variant
Dim lisp As String
For Each ObjEnt In ThisDrawing.ModelSpace
If TypeOf ObjEnt Is AcadMText Then
ObHandle = ObjEnt.Handle
lisp = "(handent " & Chr(34) & ObHandle & Chr(34) & ") "
ThisDrawing.SendCommand ("select ")
ThisDrawing.SendCommand (lisp)
ThisDrawing.SendCommand ("erase ")
End If
Next
End Sub
EXcuse me, but after ThisDrawing.SendCommand ("select ") AutoCAD waits for selecting an object by the user instead of selecting all MText automatically. What is the cause of that?
Because that's the way the SELECT command works. When you use SendCommand, you can't change the way the command works. You have to use SelectionSet filtering. Here is a post that has some code for filtering for mtext. You can search the forum for other samples.