Rather than work with a single entity, it is frequently more useful to work with groups of entities. By creating an appropriate selection set each entity within that selection set can be changed accordingly.
Explanation: the (ssget) function
(ssget [mode] [pt1] [pt2] [filter–list])
If no options are specified, (ssget) prompts the user through AutoCAD’s general “Select objects:” prompt.
Command: (setq SS1 (ssget))
Select objects: . . . <select interactively> . . .
Select objects: <enter>
<Selection set 1>
- The (ssget) function returns a selection set. This is a unique data type we haven’t discussed before. What function can we use to find the data type of what is returned by (ssget)?
The optional mode arguments correspond to AutoCAD selection modes:
- Selection sets contain main entities only (no attributes or polyline vertices).
- The selected objects are highlighted only when the (ssget) function is used without any arguments.
- You can have up to 128 open selection sets at one time. If more are attempted, AutoLISP returns nil to all (ssget) tries. To close a selection set variable, set its value to nil.
In this practice you will create a new “Move and Rotate” command by selecting objects, moving them and then rotating them. Estimated time for completion: 10 minutes.
Steps to the solution
1. Use (ssget) to have users select the objects to move and rotate.
2. Get the basepoint, second point, and rotation angle from the user.
3. Run the MOVE and ROTATE commands using the information gathered above.
(defun C:MoveRotate ()
(setq CE-SAVE (getvar “cmdecho”))
(setvar “cmdecho” 0)
(setq SS (ssget))
(setq CP (getpoint “\nBase point: “))
(setq PT2(getpoint “\nSecond point: “))
(setq ANG (getdist “\nRotation Angle: “))
(command “move” SS “” CP PT2)
(command “rotate” SS “” PT2 ANG)
(setvar “cmdecho” CE-SAVE)
- A complete solution to this exercise is on your class disk as MOVEROTATE-A.LSP