@Rick_Tolleshaug_TSC: the adapted code now results in 3 lines:
16,,RAL 9005 zwart
16,,RAL 9010 wit
65,,
That's not quit what I expected
@daniel_cadext: I tried this one, combined with the table2excel-LISP of @Sea-Haven. But now I (still) have to select the blocks manually. Besides that, I'm not getting the visibility states and the attribute I need.
Just because it can I used AI, to see how far it gets. I asked for exporting blocks with blockname starting with ID, EX, EP, EW, exporting count, vis state and attribute, sending it to an excelsheet DWGexport.xls, saving the file with the dwg-name in the same directory as the drawing. It comes up with this code:
(defun ExportBlocksToExcel ()
(vl-load-com) ; Laad de VLISP COM functies
;; Excel starten en sjabloonpad instellen
(setq excel-app (vlax-get-or-create-object "Excel.Application"))
(setq template-path "T:\\ACAD2008\\BIB\\Excel\\DWGexport.xls") ; Gebruik .xls versie
;; Controleer of het bestand beschikbaar is
(if (not (findfile template-path))
(progn
(alert (strcat "Excel sjabloon niet gevonden op de opgegeven locatie: " template-path))
(exit)
)
)
;; Probeer het Excel-bestand te openen
(setq workbook (vl-catch-all-apply 'vlax-invoke-method (list (vlax-get excel-app 'Workbooks) 'Open template-path)))
(if (vl-catch-all-error-p workbook)
(progn
(alert (strcat "Kan sjabloon niet openen. Controleer bestandstoegang of extensie: " template-path))
(exit)
)
)
;; Selecteer het eerste tabblad
(setq sheet (vlax-invoke-method workbook 'Sheets 'Item 1))
;; Haal de tekening op
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq dwg-path (vla-get-FullName doc))
(setq dwg-name (vl-filename-base dwg-path))
;; Doorloop alle blocks en verzamel informatie
(setq blocks (vla-get-Blocks doc))
(setq row 2) ; Begin op rij 2
(vlax-for block blocks
(setq block-name (strcase (vla-get-Name block)))
;; Filter op bloknaam
(if (or (wcmatch block-name "ID*")
(wcmatch block-name "EX*")
(wcmatch block-name "EP*")
(wcmatch block-name "EW*"))
(progn
(setq count 0 visibility "N/A" attribute "")
;; Doorloop blockreferenties en haal attributen op
(vlax-for entity block
(if (eq (vla-get-ObjectName entity) "AcDbBlockReference")
(progn
(setq count (1+ count))
;; Controleer op visibility, zet om naar string
(if (vlax-property-available-p entity 'EffectiveName)
(setq visibility (vl-princ-to-string (vla-get-EffectiveName entity))))
;; Attributen samenvoegen als string
(vlax-for att (vla-get-Attributes entity)
(setq attribute (strcat attribute (vl-princ-to-string (vla-get-TextString att)) " "))
)
)
)
)
;; Zet elke waarde om naar een string vóór het schrijven naar Excel
;; Schrijf Blocknaam
(vl-catch-all-apply (function (lambda ()
(vlax-put (vlax-invoke-method sheet 'Cells row 1) 'Value (vl-princ-to-string block-name))
)))
;; Schrijf Aantal (als string)
(vl-catch-all-apply (function (lambda ()
(vlax-put (vlax-invoke-method sheet 'Cells row 2) 'Value (itoa count))
)))
;; Schrijf Visibility (als string)
(vl-catch-all-apply (function (lambda ()
(vlax-put (vlax-invoke-method sheet 'Cells row 3) 'Value visibility)
)))
;; Schrijf Attributen (als string)
(vl-catch-all-apply (function (lambda ()
(vlax-put (vlax-invoke-method sheet 'Cells row 4) 'Value attribute)
)))
;; Ga naar de volgende rij
(setq row (1+ row))
)
)
)
;; Opslaan in .xls-formaat
(setq save-path (strcat (vl-filename-directory dwg-path) "\\" dwg-name ".xls"))
(if (vl-catch-all-error-p
(vl-catch-all-apply 'vlax-invoke-method (list workbook 'SaveAs save-path :vlax-false 56))) ; Type 56 voor .xls-bestand
(alert "Fout bij het opslaan van het Excel-bestand.")
)
;; Excel zichtbaar maken en opruimen
(vlax-put excel-app 'Visible :vlax-true)
(vlax-release-object sheet)
(vlax-release-object workbook)
(vlax-release-object excel-app)
(princ "Export voltooid en opgeslagen.")
)
(ExportBlocksToExcel)
(princ)
On this, it opens the correct excel-sheet, but ends with: ; error: ActiveX Server returned an error: Type mismatch