- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Select through script or AutoLisp
Hi all,
I would like to select on screen some entities based on their handle. I already have a list of their handles in excel and I want to feed this list into a command and have the entities selected on screen. I can use VBA to export the list to an scr or lsp file, but unfortunately I use AutoCAD LT and I cannot use VBA all the way.
Please note that I am not looking into selecting them on screen by clicking on each individual entity.
I have tried the AutoLisp selection set manipulation commands and I get back the creation of selection sets, but I never manage to make any of those sets to actually "materialise" as selection on screen, which is what I want. I essentially need this as a way to select the AutoCAD LT entities from excel and continue the interaction on them in AutoCAD LT.
What I have tried so far is to use VBA to generate a scr file utilising the SELECT and HANDENT commands. When I copy and paste its content in the command line, it works. When I try to run it as a script it does not, although there are no errors in the command line history.
The closest I can get so far is to use VBA to put the commands in the Clipboard and paste it in command line, but is there any better way to do this?
Thanks a lot in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks, I appreciate the help!
I presume that the intention has been to replace the "move" command with the "select" one and that the use of the "move" command serves as demonstration that the objects are selected correctly. The problem is that "select" is kind of special and still does not work. As a matter of fact, "move" would also work with a simpler setout, without the need for a lambda function.
My problem is not feeding objects to just any command like "move" by handle. This is not a problem. The problem is feeding them specifically to the "select" command (or any other command with a similar effect should any exists) and actually watch the objects become selected on screen, with their grips etc. Then, having the objects selected on screen, I can do any other desired operations further as if I had selected the objects by hand. I do appreciate the idea about a lambda function nevertheless!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Then use (sssetfirst nil ss) and somehow create a selection set.
In my example it could be
(sssetfirst nil ((lambda ( / s) (setq s (ssadd)) (foreach h '("149D" "149C") (ssadd (handent h) s)))))
Also you can try to use PSELECT instead of SELECT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I think your biggest problem is your using say LT2024 or 25, these do not support the get "Aplication" method which is what you need to talk to Excel or Excel to talk to CAD. So you will need to do say write a file via Excel VBA or read a csv file getting the handle ID. A re-arrange of the @ВeekeeCZ code.
I think Bricscad Lite supports get Application. I have Pro version. Some one may answer.
This is not supported
(setq myxl (vlax-get-or-create-object "excel.Application"))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can control the visibility of selection sets using sssetfirst.
Edit: d'oh! Didn't see BeekeeCZ 's post.
(defun c:hand_sel ()
(setq ss_hands (ssadd))
(setq hand_list (list "a1" "a2" "a3"));<-----Set your Handles from the CSV file here
(foreach n hand_list (ssadd (handent n) ss_hands))
(sssetfirst nil ss_hands)
(princ)
)
Win 11 Pro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@komondormrex great idea just let Excel do the work, did you do a bit of VBA macro so read selection and convert to a single multi value string? Then make the string to be copied.
Threw the question at Copilot and got some really useful starting code and made some changes to it.
Sub JoinColumnValues()
Dim lastRow As Long
Dim i As Long
Dim joinedValues As String
Dim delimiter As String
' Specify the delimiter (e.g., a comma)
delimiter = " "
' Find the last row in column A with data
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
' Loop through each cell in column A
For i = 1 To lastRow
If Cells(i, 1).Value <> "" Then
If joinedValues = "" Then
joinedValues = Chr(34) & Cells(i, 1).Value & Chr(34)
Else
joinedValues = joinedValues & delimiter & Chr(34) & Cells(i, 1).Value & Chr(34)
End If
End If
Next i
joinedValues = "(sssetfirst nil ((lambda ( / s) (setq s (ssadd)) (foreach h '(" & joinedValues & ") (ssadd (handent h) s)))))"
' Output the joined values into a specific cell (e.g., cell B1)
Range("C1").Value = joinedValues
' Inform the user
MsgBox "Values have been joined and placed in cell B1!"
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Creating the string and pasting it in the command line works. It even works with a simpler setup using the "HANDENT" command. But as long as you place the same text in a script file and try to run it, it does not. If rather than "SELECT" you apply the same operation to another command e.g. "MOVE", it works from the script file as well, as expected. But "SELECT" seems an edgy exception.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there and apologies for taking that long to respond. Unfortunately, this yields an error and the "PSELECT" command seems not existing in the LT version, To be honest I barely understand how the code works, so it could be myself not using it right. I think I'll go with the option of creating the lisp command as text, put in the clipboard with VBA and then just paste it in the command line. For some reason, it works.
The reason why I insisted on script files is that I hoped to push buttons from excel, create a script file and then run it always using the same command in the AutoCAD LT command line. So, e.g. making a command "AAA" that essentially executes "whatever the commands in X.scr file say" and then just push an Excel button each time to alter the commands in the X.scr file. This seamed neat, I had the workflow in mind and then it stuck on the "SELECT" command.
Anyways, thanks for the help, I think I'll go for the Clipboard option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As I mentioned no idea why Autodesk did not do a 100% lisp implementation, then you would not have problems. You can save the macro to a file and import it into the current Excel.