Search code examples
lispautolisp

AutoLISP - Selecting/Moveing Object Multiple Times Using Coordinates Autocad


is there any way to select entities given the coordinates?

Example: I want to select entities from (-21,8) to (21,-22) <----- upper left and lower right of a rectangle, respectively. And select entities from (150,8) to (192,-22). And select entities from (321,8) to (363,-22). And select entities from (492,8) to (534,-22).

But I need to select them without selecting entities between those respective areas. There are multiple areas like this. So it would be better to select them all rather than select them one by one.

I need to select these objects and move the objects selected 500 units down.

I used (ssget "_C" '(-21 8) '(21 -22)) but to select multiple times it doesn't work.


Solution

  • You can obtain multiple selection sets using separate ssget expressions, and then supply them all to a single call to the MOVE command (or alternatively, iterate over the objects in each set and use the ActiveX move method).

    For example:

    (setq s1 (ssget "_C" '(-21 8) '( 21 -22))
          s2 (ssget "_C" '(150 8) '(192 -22))
          s3 (ssget "_C" '(321 8) '(363 -22))
          s4 (ssget "_C" '(492 8) '(534 -22))
    )
    (if (or s1 s2 s3 s4)
        (progn
            (command "_.move")
            (if s1 (command s1))
            (if s2 (command s2))
            (if s3 (command s3))
            (if s4 (command s4))
            (command "" "_non" '(0 0) "_non" '(0 -500))
        )
    )
    

    Since you are using a graphical selection mode string (C [Crossing]) you must ensure that the target objects are all visible within the drawing area in order to be selected.