Jump to content

How to know if a DXF property exist in an autocad object with lisp


Recommended Posts

Posted

Hi dear team. Wish you a great day

 

I was wondering if there is a way to know if a DXF property exist on selected objects:

For example:

(setq ss (ssget "something"))

(if (exist DXF code 3 in ss) (prompt "\nThe DXF code 3 exist in selected object") (prompt "\nThe DXF code 3 doesn`t exist in selected object"))

Posted (edited)

@JovanG Look at using (assoc), it returns nil if the DXF code is not present.

 

Example:

(assoc 3 (entget (car (entsel))))

Paste this at the command line and select a longer mtext and a short mtext

 

If you are iterating through the selection set it would be something like this snippet of code:

(defun massoc (key alist / x nlist)
   (foreach x alist
      (if
         (eq key (car x))
         (setq nlist (cons x nlist))
      )
   )
   (reverse nlist)
) ;defun

(setq cnt -1)
(repeat (sslength ss)
  (setq en (entget (ssname ss (1+ cnt))))
  (if (assoc 3 en)
     (progn
         (setq str
             (apply 'strcat
			    (cons
                   (mapcar 'cdr (massoc 3 en))
                   (cdr (assoc 1 en))
                )
             )
         )
         ; .. do something ..
      )
     (progn
        (setq str (cdr (assoc 1 en)))
        ; .. do something ..
     )
   )
)

EDIT - corrected! The (apply) statement should've has 'strcat, not 'append

Edited by pkenewell
  • Like 1
Posted
19 minutes ago, pkenewell said:

Look at using (assoc), it returns nil if the DXF code is not present.

Excellent! Thank you very much @pkenewell. That was just what I needed

  • Like 1

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...