Combine two lisp routines for Attribute manipulation

Combine two lisp routines for Attribute manipulation

cbenner
Mentor Mentor
1,115 Views
4 Replies
Message 1 of 5

Combine two lisp routines for Attribute manipulation

cbenner
Mentor
Mentor

Good morning...

I've borrowed and modified two routines that I found online.  Where possible I kept the original author's name intact for credit where credit is due.  They are attached to this post.

 

The first is mav.lsp by Lee Mac.  This one takes the attribute values (with exceptions) from one block and transfers them to a different block with the same attribute tags.  This works like a charm, as you would expect from one of Lee's programs.  

 

The second (atts.lsp) is one I compiled myself from some code I found, and I can't remember the source,... my apologies and thanks to the original author.  This one looks at a block for two specific attribute tags, and concatenates the values into a string, separated by a hyphen.

 

What I would like to do is combine these two, so that the "Mav" portion copies (hidden) attributes from the top symbol in the image below, and places them into the second symbol.  The attribute containing the HX - 250 would be the exception l would include in Lee's code.  For that portion, I would like to use the code from "Atts", to grab the two attributes visible in the top symbol, concatenate them and populate the HX-250.  Notice that, right now, in the atts program I am only grabbing the values and alerting them... this was just to see if I could do it.  If I had to, I could keep these separate and do this in two steps, but it would be so nice to be able to do this with one step.

 

Any ideas on how to combine these?  Again, I WILL give credit where it is due.  Any help would be appreciated.

 

tags.JPG

 

 

0 Likes
Accepted solutions (1)
1,116 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

 

If I do not misundertand your request is specific to some attributed block, in this case, you should attach the block.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

cbenner
Mentor
Mentor
0 Likes
Message 4 of 5

_gile
Consultant
Consultant
Accepted solution

Try this:

 

(defun c:copyatt (/ getAttribs src elst atts ss i br att)
  (defun getAttribs (br / att values)
    (setq att (entnext br))
    (while (= "ATTRIB" (cdr (assoc 0 (setq elst (entget att)))))
      (setq values (cons (cons (cdr (assoc 2 elst)) (cdr (assoc 1 elst))) values)
            att    (entnext att)
      )
    )
    (reverse values)
  )
  (if (and (setq src (car (entsel "\nSelect source block: ")))
           (setq elst (entget src))
           (= (cdr (assoc 0 elst)) "INSERT")
           (= (cdr (assoc 2 elst)) "EquipTag")
           (setq atts (getAttribs src))
      )
    (if (setq ss (ssget '((0 . "INSERT") (2 . "EquipID"))))
      (repeat (setq i (sslength ss))
        (setq br  (ssname ss (setq i (1- i)))
              att (entnext br)
        )
        (while (= "ATTRIB" (cdr (assoc 0 (setq elst (entget att)))))
          (if (= (cdr (assoc 2 elst)) "NO")
            (entmod
              (subst (cons 1 (strcat (cdr (assoc "ETID1" atts)) "-" (cdr (assoc "ETAG" atts))))
                     (assoc 1 elst)
                     elst
              )
            )
            (entmod
              (subst (cons 1 (cdr (assoc (cdr (assoc 2 elst)) atts))) (assoc 1 elst) elst)
            )
          )
          (setq att (entnext att))
        )
      )
    )
    (prompt "\nInvalid selection")
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes