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

Please help with assoc list.

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
M.Red
545 Views, 4 Replies

Please help with assoc list.

This procedure "Works".  If I uncomment the line with "(Assoc 10)" it surely does not.  Pleas help and explain what I am doing wrong.  My simplistic understanding is that it should just add the XYZ coordinate of the attribute, but it actually just causes the procedure to return NOTHING.

 

(defun BlkAttrs ()
 (setq Blks (ssget (list (cons 2 "*"))))   ;Get list of Blocks
 (setq NBlks (sslength Blks))
 (setq Nblks (- NBlks 1))  ;Get count of Blocks
 (Setq iBlk 0)   ;Counter: Initalize

 (While (<= iBlk nBlks)  ;Loop through each
  (setq Blki (ssname Blks iblk)) ;Select a specific Block
  (Setq AttLst nil)  ;Clear last pass

  (while    ;Get all TAG & Value Attributes
   (= "ATTRIB" (cdr (assoc 0 (setq BlkLst (entget (setq BlkI (entnext BlkI )))))))
   (setq AttLst (append Attlst (list BlkLst)))

  );End While "ATTRIB"

  ;Consolidate them into a single list
  (Setq BlkAttr
                                              (mapcar '(lambda (x)
                                                     (cons
                                                           (cdr (assoc 2 x))
                                                           (cdr (assoc 1 x))
;;;                                                           (Cdr (assoc 10 x))
                                                                                       )) AttLst))

  ;Print the list
  (princ BlkAttr)

  (setq iBlk (+ iBlk 1))  ;Increment loop

 );End iBlk

); End defun

4 REPLIES 4
Message 2 of 5
DavidBethel
in reply to: M.Red

 

Maybe this wil help:

 

(defun c:BlkAttrs (/ blks i en an ad BlkAttr)
 (and (setq Blks (ssget (list (cons 0 "INSERT")
                              (cons 66 1))))
      (setq i 0)
      (while (setq en (ssname Blks i))
             (setq an (entnext en)
                   ad (entget an))
             (while (= "ATTRIB" (cdr (assoc 0 ad)))
                    (setq BlkAttr (cons (list (cdr (assoc 2 ad))
                                              (cdr (assoc 1 ad))
                                              (cdr (assoc 10 ad))) BlkAttr))
                    (setq an (entnext an)
                          ad (entget an)))
             (setq i (1+ i))))
 (prin1 BlkAttr)
 (prin1))

(cons 0 "INSERT")(cons 66 1)  filters for inserts with attributes

 

As to the error, 1 of your problems is BlkAttr is a list and needs to be used in conjunction with prin1.  

 

-David

Message 3 of 5
M.Red
in reply to: DavidBethel

Thanks.  I obviously still have a LONG way to go w/ Autolisp.  This works quite nicely.

Message 4 of 5
DavidBethel
in reply to: M.Red

You're welcome.  We all had to start somewhere.  Most autolisp peeps are self taught with a LOT of help from contrubutors.  -David

Message 5 of 5
BlackBox_
in reply to: DavidBethel


@DavidBethel wrote:

... We all had to start somewhere.  Most autolisp peeps are self taught with a LOT of help from contrubutors.


This.



"How we think determines what we do, and what we do determines what we get."

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

Post to forums  

Autodesk Design & Make Report

”Boost