;Block Attributes to Access (via txt linked to access)
;The following is a variant of blk_lst.lsp of Bonus/Cadtools of Acad14
;it may be missing in A2000 though.
;This works for one block picked at a time.
;Try it -if the linking of txt file to Access is acceptable,
;we shall preceed this routine with an ssget function
;to make it do for a bunch of blocks at one pick.
;please modify this line, down below, before use.
;Put here the txt file name linked in your Access Databank.
;(setq f1 (open "C:/Acad/MyFile.txt" "a"

)
;Aceess allows directly linking of txt files - over Menu>Files>
;So, a comma separated txt file is practically an access table.
;and the table updates automatically each time Access is opened.
;the txt is linked only once.
;See if comma separation is enough. If not, we can add the quote marks in the code below.
;Frankly, it is too much trouble to write directly into Access mdb file, given the convenience
;of linking txt to Access.
;for each block
(defun c:attribex (/ nam b en1 en constcnt varcnt)
(setq myLine ""

(setq en (car (entsel)))
(if (not en) (progn (prompt "\nNothing selected."

(quit)))
(if (/= "INSERT" (dxf 0 (entget en))) (progn (prompt "\nNot a block."

(quit)))
(setq bnam (dxf 2 (entget en))
constcnt 0 varcnt 0 en1 en)
; list constant attributes:
(if (setq b (tblsearch "block" bnam))
(if (setq en (dxf -2 b))
(progn
(pratt en "ATTDEF" 'constcnt)
(while (setq en (entnext en))
(pratt en "ATTDEF" 'constcnt)))
(prompt (strcat "\nNo entities in block " bnam)))
(prompt (strcat "\nBlock " bnam " not found."

))
; list variable attributes:
(while (/= "SEQEND" (dxf 0 (entget (setq en1 (entnext en1)))))
(pratt en1 "ATTRIB" 'varcnt))
(prompt (strcat "\nBlock " bnam " has " (itoa constcnt) " constant attributes."

)
(prompt (strcat "\nBlock " bnam " has " (itoa varcnt) " variable attributes."

)
(princ "\n"

(princ myLine)
(AppendToFile myLine)
(princ)
)
;---------
(defun dxf (n ed) (cdr (assoc n ed)))
;--------
;==================================================================
; pratt - print attribute ins point, tag, and value & incr counter:
(defun pratt (en type pcnt)
(setq ed (entget en))
(if (= type (dxf 0 ed))
(if (or (/= "ATTDEF" (dxf 0 ed)) ; variable attribute: ATTRIB
(/= 0 (logand 2 (dxf 70 ed)))) ; const: ATTDEF & const flag
(progn
(set pcnt (1+ (eval pcnt)))
;(print (dxf 10 ed))
;(prin1 (dxf 2 ed))
;(princ ": "

(setq myLine (strcat myLine (dxf 1 ed) ","

)
;(prin1 (dxf 1 ed))
)))
)
;-----
(defun appendToFile(MyLine)
(setq f1 (open "C:/Acad/MyFile.txt" "a"

)
;(princ "\n"

(princ myLine f1)(princ "\n"

(write-line myline f1)(print)
(close f1)
)