Hello everyone!
Found this lisp in the forums by Jim Claypool which grabs attributes from a block within xrefs. Works nicely but I need to only choose some specific tags (tag01, tag02, tag03) and write the attribute value to mleader. Please help! Thanks in advance and Happy Thanksgiving to everyone!!!!!
(defun c:xrefatts () (setq ename (nentsel "\nSelect block in XREF: ")) (if (= (length (nth 3 ename)) 2) (progn (setq attlist (setq obj (vlax-ename->vla-object (car (nth 3 ename)))) ) (mapcar '(lambda (Att) (cons (vla-get-TagString Att) (vla-get-TextString Att)) ) (vlax-invoke Obj "GetAttributes") ) ) ;else (alert "Object selected is not a block") ) )
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Hi JCprog,
the Jim Claypool's 'xrefatts' return an association list of dotted pairs with 'TAG . value'.
Using Jim Claypool's 'xrefatts', slightly modified, testing for those specific tags and passing the returned to the 'mleader' command, perhaps something like this will do the trick...
(defun c:demo (/ xrefatts att y lst) ;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/extract-attribute-values-from-xref/m-... ;; original by Jim Claypool ;; modified by me (defun xrefatts (/ Att attlist ename Obj) (if (setq ename (nentsel "\nSelect block in XREF: ")) (if (= (length (nth 3 ename)) 2) (progn (setq attlist (setq obj (vlax-ename->vla-object (car (nth 3 ename)))) ) (mapcar '(lambda (Att) (cons (vla-get-TagString Att) (vla-get-TextString Att)) ) (vlax-invoke Obj "GetAttributes") ) ) ) ) ) (if (setq lst (xrefatts)) (progn (foreach x '("tag01" "tag02" "tag03") (if (setq y (assoc x lst)) (progn (prompt (strcat "\nStart Mleader for TAG < " (car y) " >: \n")) (command "_.mleader" "\\" "\\" (cdr y)) ) (prompt "\nAttribute TAG < " x " > was not found! ") ) ) ) (prompt "\nSelected object was not a block!") ) (princ) )
Hope that helps
Henrique
Thanks Henrique for the reply. It works well but I was hoping for the tags to be listed in one mleader
e.g.
tag01Value
tag02Value
tag03Value
....and shouldnt matter if attribute is blank.
You're welcome, JCprog
Try
(defun c:demo (/ xrefatts att y lst) ;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/extract-attribute-values-from-xref/m-... ;; original by Jim Claypool ;; modified by me (defun xrefatts (/ Att attlist ename Obj) (if (setq ename (nentsel "\nSelect block in XREF: ")) (if (= (length (nth 3 ename)) 2) (progn (setq attlist (setq obj (vlax-ename->vla-object (car (nth 3 ename)))) ) (mapcar '(lambda (Att) (cons (vla-get-TagString Att) (vla-get-TextString Att)) ) (vlax-invoke Obj "GetAttributes") ) ) ) ) ) (if (setq lst (xrefatts)) (progn (setq txt "") (foreach x '("tag01" "tag02" "tag03") (if (setq y (assoc x lst)) (setq txt (strcat txt (car Y) "=" (cdr y) "\\P")) (prompt "\nAttribute TAG < " x " > was not found! ") ) ) (if (/= txt "") (command "_.mleader" "\\" "\\" (vl-string-right-trim "\\P" txt)) ) ) (prompt "\nSelected object was not a block!") ) (princ) )
Henrique
thats weird! now it works perfectly....just one more thing.....
now it list as:
tag01=value01
tag02=value02
tag03=value03
can it just be:
value01
value02
value03
Edit: Disregard the above......This works perfectly!
I modified this line (setq txt (strcat txt (cdr y) "\\P"))
Thanks a million Henrique!
Change
(setq txt (strcat txt (car Y) "=" (cdr y) "\\P")) ;; to (setq txt (strcat txt (cdr y) "\\P"))
EDIT: localize the txt variable, I forgot....
(defun c:demo (/ xrefatts att y lst txt)
Henrique