Jump to content

LISP to select lines and text according to "Z" values


Recommended Posts

Posted (edited)

If all the primitives (TEXT,MTEXT,INSERT,LINE,LWP,Circle,Mleader,Dimension) are perceived as objects, 
then you can use this code:
 

;; Set coordinates of objects (TEXT,MTEXT,INSERT,LINE,LWP,Circle,Mleader,Dimension) Z in 0
(defun zeroz-in-list (lst /)
  (cond
    ;; The list of coordinates-vertex
    ((and (listp lst)
          (= (length lst) 2)
          (numberp (car lst))
          (numberp (cadr lst)))
      ;; if only XY - expanding to XYZ
      (list (car lst) (cadr lst) 0.0)
    )
    ((and (listp lst)
          (= (length lst) 3)
          (numberp (car lst))
          (numberp (cadr lst))
          (numberp (caddr lst)))
     ;; if already XYZ -  just do Z=0.0
     (list (car lst) (cadr lst) 0.0)
    )
    ;; If it's a large list, it's probably nested
    ((listp lst)
     (mapcar 'zeroz-in-list lst)
    )
    (t lst)
  )
)

(defun c:ObjZ0 (/ ss n e el newel)
  (prompt "
Select objects (all types, including polylines, mleader, dimension): ")
  (if (setq ss (ssget))
    (progn
      (setq n 0)
      (while (< n (sslength ss))
        (setq e (ssname ss n)
              el (entget e)
              newel nil
        )
        (foreach pair el
          (cond
            ;; height LWPOLYLINE (code 38)
            ((and (= (car pair) 38) (numberp (cdr pair)))
             (setq newel (cons (cons 38 0.0) newel))
            )
            ;;Point codes (for example, 10, 11, 12...), etc.
            ((and (numberp (car pair))
                  (not (= (car pair) 210))) ; Don't touch the normal
             (if (listp (cdr pair))
                 (setq newel (cons (cons (car pair) (zeroz-in-list (cdr pair))) newel))
                 (setq newel (cons pair newel))
             )
            )
            ;; The rest
            (t (setq newel (cons pair newel)))
          )
        )
        ;; Restoring order and modifying the object
        (entmod (reverse newel))
        (setq n (1+ n))
      )
    )
  )
  (princ)
)

If the Z coordinate is not displayed in the properties (example, for dimensions, for Mleader), then you need to use the _LIST command.

Don't think of me as a programmer...
The code is written using AI.

Edited by Nikon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...