Error while retrieving block attributes

Error while retrieving block attributes

Lauri_LehtomakiUJAHS
Explorer Explorer
392 Views
3 Replies
Message 1 of 4

Error while retrieving block attributes

Lauri_LehtomakiUJAHS
Explorer
Explorer

I'm trying to loop through block and retrieve attributes into a list of dotted pairs (tag . value).

 

In row 20 the code runs into an error "error: bad function: "VALUE"" where VALUE is the attribute value. However if I do this row by row from command prompt I'm able to store these values without any errors. While loop and cond seems to work fine. What am I missing here?

 

(defun c:listAttributes (/ attributes endseq currentBlock entTemp keyword attTag attValue) 
  
  (setq currentBlock (entget (car (entsel))))

  (setq endseq nil)

  (setq entTemp currentBlock)

  (while (null endseq) 

    (setq entTemp (entget (entnext (cdr (assoc -1 entTemp)))))

    (setq keyword (cdr (assoc 0 entTemp)))

    (cond

      ( (= keyword "ATTRIB")
       
        (
          (setq attValue ((cdr (assoc 1 entTemp))))
          (setq attTag (cdr (assoc 2 entTemp)))
          (setq attributes (append attributes (list (cons attTag attValue))))
        )
      )

      ( (= keyword "SEQEND")
        (setq endseq T)  
      )
      
      (t nil)
      
    )
  )
)

 

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

pbejse
Mentor
Mentor
Accepted solution

@Lauri_LehtomakiUJAHS wrote:

...In row 20 the code runs into an error "error: bad function: "VALUE"" where VALUE is the attribute value.  While loop and cond seems to work fine. What am I missing here?


You had one too many parenthesis

   ( (= keyword "ATTRIB") 
        (
          (setq attValue ((cdr (assoc 1 entTemp))))
          (setq attTag (cdr (assoc 2 entTemp)))
          (setq attributes (append attributes (list (cons attTag attValue))))
        )
      )

the Fix

(defun c:listAttributes (/ attributes endseq currentBlock entTemp keyword attTag attValue) 
  (setq currentBlock (entget (car (entsel))))
  (setq endseq nil)
  (setq entTemp currentBlock)
  (while (null endseq) 
    (setq entTemp (entget (entnext (cdr (assoc -1 entTemp)))))
    (setq keyword (cdr (assoc 0 entTemp)))
    (cond
      ( (= keyword "ATTRIB")
       
          (setq attValue (cdr (assoc 1 entTemp)))
          (setq attTag (cdr (assoc 2 entTemp)))
          (setq attributes (append attributes (list (cons attTag attValue))))
      )
      ( (= keyword "SEQEND")
        (setq endseq T)  
      )
      
      (t nil)
      
    )
  ) attributes
)

HTH

0 Likes
Message 3 of 4

Lauri_LehtomakiUJAHS
Explorer
Explorer
Thanks! Seems to be too obvious to detect.
0 Likes
Message 4 of 4

pbejse
Mentor
Mentor

@Lauri_LehtomakiUJAHS wrote:
Thanks! Seems to be too obvious to detect.

We all been there.

You are welcome @Lauri_LehtomakiUJAHS 

 

0 Likes