Description
This script replicates the behavior of SelLast from Rhino in AutoCAD. However, in its current state, it does not allow to select multiple last elements. It only selects one last element. In the scenaraio where you copy paste a bunch of objects, it randomly selects one of them.
Code
(defun c:SelLast ()
(setq last-entity (entlast)) ; Get the last created entity
(if last-entity
(progn
(sssetfirst nil (ssadd last-entity)) ; Set selection to the last entity
(princ "\nLast entity selected.")
)
(princ "\nNo recent entity to select.")
)
(princ) ; Exit quietly
)Installation
- Save this code in a file as
SelLast.lsp. - In AutoCAD, use the APPLOAD command to load the
SelLast.lspfile.
Keyboard shortcut
To assign Ctrl+K as a keyboard shortcut for your new SelLast command in AutoCAD, you can set this up in the CUI (Customize User Interface) editor. Here’s how:
- Open the CUI Editor:
- Type
CUIin the AutoCAD command line and pressEnterto open the Customize User Interface editor.
- Type
- Locate Keyboard Shortcuts:
- In the CUI dialog, navigate to the Keyboard Shortcuts section in the Customization panel on the left side.
- Expand Keyboard Shortcuts and then expand Shortcut Keys.
- Create a New Shortcut:
- Right-click on a randome Shortcut Keys and select Duplicate. This will duplicate a new shortcut key entry that we will modify.
- Configure the New Shortcut:
- In the Properties panel on the right, set these properties:
- Name: Enter a descriptive name like “Select Last Entity (SelLast)“.
- Macro: This is the command to run your LISP function. Type:
^C^C(if (not (fboundp 'SelLast)) (load "SelLast.lsp")) SelLast - Key(s): Click in the Key(s) field, then press
Ctrl+Kon your keyboard to assign it as the shortcut.
- Apply and Save:
- Click Apply and then OK to close the CUI editor.
- Test the Shortcut:
- After setting it up, try pressing
Ctrl+Kin AutoCAD. It should now run theSelLastfunction and select the last created entity.
- After setting it up, try pressing
This shortcut will now be saved in your AutoCAD environment, so you can quickly select the last object with Ctrl+K.