Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attributes inside Xref to mleader

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
JCprog
411 Views, 7 Replies

Attributes inside Xref to mleader

Hello everyone! Smiley Happy

 

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!!!!!Smiley LOL

 

(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")
)
)

 

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: JCprog

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

EESignature

Message 3 of 8
JCprog
in reply to: hmsilva

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.

Message 4 of 8
hmsilva
in reply to: JCprog

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

EESignature

Message 5 of 8
JCprog
in reply to: hmsilva

it says Unknown command "Tag01=Value01\PTag02=\PTag03=Value03" and it stops and creates only the leader.

Message 6 of 8
hmsilva
in reply to: JCprog


@JCprog wrote:

it says Unknown command "Tag01=Value01\PTag02=\PTag03=Value03" and it stops and creates only the leader.


I can't reproduce that behavior, post a sample block...

 

EDIT: Did the previous mleaders from the previous code worked ok?

 

Henrique

EESignature

Message 7 of 8
JCprog
in reply to: hmsilva

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!Smiley Very Happy

Message 8 of 8
hmsilva
in reply to: JCprog

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

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost