AutoCAD LT 2024 LISP similar to ATTOUT

roberto_ortizKVL98
Explorer

AutoCAD LT 2024 LISP similar to ATTOUT

roberto_ortizKVL98
Explorer
Explorer

Hi,

Attached is a LISP to extract block attributes to a CSV file. The issue is that the handler does not have a prefix single quote when exported to the CSV file, unlike when we use ATTOUT in AutoCAD. Perhaps someone can help with this and create a LISP similar to ATTIN. 

0 Likes
Reply
Accepted solutions (2)
1,075 Views
15 Replies
Replies (15)

LDShaw
Advocate
Advocate

This thread had similar issues. Perhaps it can help you out. I have full autocad so my help is limited.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/an-automation-that-requires-excellen...

ec-cad
Advocate
Advocate
Accepted solution

Try this little change. Adds a ' character to Handle.

;; Get the handle and block name
   (setq handle (cdr (assoc 5 ent)))
     (setq handle (strcat "'" handle)); <------------ add this line
   (setq blockName (cdr (assoc 2 ent)))

 

ECCAD

roberto_ortizKVL98
Explorer
Explorer
Thanks for the help. Now it shows in the CSV file.
0 Likes

roberto_ortizKVL98
Explorer
Explorer

Thanks for all your responses. The last responder resolved the issue, but now I'm facing a new challenge. I have a code similar to ATTIN, and it appears it can't locate the handler, with or without the 'single quote' prefix. Can anyone help identify the issue with the Lisp?

 

The exact error 

Block with handle CBC6 not found.
Block with handle CBC6 not found.
Block attributes updated successfully.

 

2 blocks were selected on this example.

0 Likes

ec-cad
Advocate
Advocate

In this snipit of code: you did not 'increment' the index variable "i".

 

(repeat (setq i (length headers))
                  (setq attrTag (nth i headers))     ;; Get the attribute tag from header
                  (setq attrVal (nth i attrList))    ;; Get the corresponding attribute value from CSV

                  ;; If the attribute exists, update its value
                  (setq ent (entget (entnext block)))
                  (while (and ent (= (cdr (assoc 0 ent)) "ATTRIB"))
                    (if (equal (cdr (assoc 2 ent)) attrTag)
                      (entmod (subst (cons 1 attrVal) (assoc 1 ent) ent))  ;; Update the attribute value
                    )
                    (setq ent (entget (entnext block))) ;; Move to the next attribute
                  )
                )

 

Unless for each line in the .csv, there is only (1) Attribute Tag and Value.

If the (setq block (handent handle)) line doesn't get the 'entity', maybe try

(setq block (ssget "x" (list (cons 5 handle))))

 

 

ECCAD

0 Likes

roberto_ortizKVL98
Explorer
Explorer

Thanks, ec-cad But what about the "Block with handle CBC6 not found?" This CBC6 was the first block on the list.

0 Likes

ec-cad
Advocate
Advocate

I would need to look at the 'data' and the drawing to determine that.

Either (handent  or (ssget .. with the correct Handle string (should) work.

Looks like it's not 'finding' that particular block insert.

Also, why did it echo that not found twice ?

 

Could you upload the .csv and sample drawing ?

 

ECCAD

0 Likes

roberto_ortizKVL98
Explorer
Explorer

Here you go

0 Likes

ec-cad
Advocate
Advocate

I made up a small drawing for testing attin.lsp.

This is the 1st line of the .csv (saved as a text file, so characters show)
Handle,Block Name,ROOMAREA,ROOM#

And, after function: (readDelimitedLine ..
This is what it returns:
(HANDL BLOCK NAM ROOMARE ROOM#)
('AE ROO 444)

Looks like it is clipping off 'last' character of delimited variables.

Trying to find out why that function does that... looks good, but doesn't work.

I'll be back later.

 

ECCAD

0 Likes

ec-cad
Advocate
Advocate

And, at command prompt line, this happens.

Command: (setq line "Handle,Block Name,ROOMAREA,ROOM#")
"Handle,Block Name,ROOMAREA,ROOM#"

Command: (setq delimiter ",")
","

Command: (setq start 1)
1

Command: (setq end (vl-string-search delimiter line start))
6

Command: (setq ch (substr line start (- end start)))
"Handl"

0 Likes

ec-cad
Advocate
Advocate

Try this change in the function readDelimitedLine:

;; Helper function to split a CSV line into a list of values
(defun readDelimitedLine (line delimiter / start end valList)
  (setq start 1)
  (while (setq end (vl-string-search delimiter line start))
    (if (> end 0)(setq valList (append valList (list (substr line start (- (+ end 1) start))))))
    (setq start (+ end 2)) ;; Move start position to after delimiter
  )
  ;; Add the last value (after the last delimiter)
  (setq valList (append valList (list (substr line start))))
  valList
)

 

ECCAD

0 Likes

ec-cad
Advocate
Advocate

Now its hanging up in the while loop, checking block attributes.

Did this one 'ever' run ??

 

ECCAD

0 Likes

ec-cad
Advocate
Advocate
Accepted solution

OK, I think I got it working.

Attached.

Cheers

 

ECCAD

0 Likes

roberto_ortizKVL98
Explorer
Explorer

Thank you, ECCAD! It is indeed working. Apologize for not responding in a timely manner. Anyway, your alias fits you. Now in AutoCAD LT we have a similar function as ATTOUT and ATTIN. 

0 Likes

vladimir_michl
Advisor
Advisor

You can also try the extended ATTOUT/ATTIN tool (processes also dynamic blocks and their properties) supported in AutoCAD LT. See (free download):

https://www.cadforum.cz/en/extended-attout-attin-for-block-attribute-management-in-excel-tip14361

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

0 Likes