Looking to Capture Attribute Data - Cannot Find Code

Looking to Capture Attribute Data - Cannot Find Code

Anonymous
Not applicable
811 Views
3 Replies
Message 1 of 4

Looking to Capture Attribute Data - Cannot Find Code

Anonymous
Not applicable

Let me qualify this that I am new to lisp (well I knew it pretty well a LONG time ago).

 

I have a block that has miscellaneous attribute data in the Description attribute.

 

I am trying to find a lisp routine that does that can collect the objects on a drawing and if is on a selection set the layer will be changed (or created if the layer does not exist), if a word appears in the description.

 

Does anyone have something like that?

 

TIA

 

SaturnV

0 Likes
Accepted solutions (1)
812 Views
3 Replies
Replies (3)
Message 2 of 4

Ranjit_Singh
Advisor
Advisor
Accepted solution

If I understand correctly, there are blocks that have a TAG named "Description" and the value of this tag contains a certain word and these blocks need to go to a different layer? If so, try below code. Note the use of "Description" in the while loop. Make sure this string matches exactly the attribute tag that you want to test. Lightly tested.

(defun c:somefunc  (/ entdata etdata lan rt teststr)
 (setq rt      "nf"
       lan     (getstring t "\nEnter Layer name: ")
       teststr (getstring t "\nEnter test string: "))
 (mapcar '(lambda (x)
           (setq entdata (entget x))
           (while (and (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget (setq x (entnext x))))))) (= rt "nf"))
            (setq rt (if (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                              (= "Description" (cdr (assoc 2 etdata)))
                              (wcmatch (cdr (assoc 1 etdata)) (strcat "*" teststr "*")))
                      "f"
                      "nf")))
           (if (= rt "f")
            (progn (command-s "._-layer" "_m" lan "") (entmod (subst (cons 8 lan) (assoc 8 entdata) entdata)))))
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "INSERT") (66 . 1))))))
 (princ))
Message 3 of 4

Anonymous
Not applicable

Thanks!

Is there a line of code that can be added to prompt for a color for the layer?

 

SaturnV

0 Likes
Message 4 of 4

Ranjit_Singh
Advisor
Advisor

Try below edit.

(defun c:somefunc  (/ entdata etdata lan rt teststr)
 (setq rt      "nf"
       lan     (getstring t "\nEnter Layer name: ")
       teststr (getstring t "\nEnter test string: "))
 (mapcar '(lambda (x)
           (setq entdata (entget x))
           (while (and (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget (setq x (entnext x))))))) (= rt "nf"))
            (setq rt (if (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                              (= "Description" (cdr (assoc 2 etdata)))
                              (wcmatch (cdr (assoc 1 etdata)) (strcat "*" teststr "*")))
                      "f"
                      "nf")))
           (if (= rt "f")
            (progn (command-s "._-layer" "_m" lan "_c" pause "" "" "" "") (entmod (subst (cons 8 lan) (assoc 8 entdata) entdata)))))
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "INSERT") (66 . 1))))))
 (princ))
0 Likes