OK, I have been experimenting with the blackboard functions - but may have to resort to vl-propagate if I cannot get this working...
Below is the code I have been working on (don't laugh
) - it is designed to Extract all attributes from a list of drawings, based on a user-specified block list.
I am trying to collect all the information that I need, before attempting to write it to Excel (I realise that there exists EATTEXT, but this is also a learning exercise more than anything...)
Ok, I have highlighted the part I am struggline with:
;;; ================= Global Attribute Extractor =================
;;; by Lee McDonnell
;;;
;;; FUNCTION: MacAtt
;;;
;;; Will Retrieve all Attributes from Blocks in a user
;;; compiled list from Multiple Drawings in a Selected
;;; Directory.
;;;
;;; AUTHOR:
;;;
;;; Lee McDonnell (Copyright (c) June 2009)
;;; (Contact Lee Mac, CADTutor.net, TheSwamp.org)
;;;
;;; ADDITIONAL THANKS TO:
;;; Tony Tanzillo
;;; Tim Willey
;;;
;;; VERSION:
;;; 1.0 ~ 11.06.2009 ~ First Release
;;;
;;; ==============================================================
(defun c:MacAtt (/ *error* *acad ExFlag BlkLst
Shell fDir Dir dbx acVer ss attLst)
(vl-load-com)
;; Error Handler
(defun *error* (e)
(if ov (mapcar 'setvar vl ov))
(ObjRel (list Shell dbx *acad))
(if (not (wcmatch (strcase e) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " e " >>")))
(princ))
;; Get Block List
(while (not ExFlag)
(setq Str (getstring t "\nAdd Block Name to List [Space to View List]: "))
(cond ((eq "" Str)
(setq ExFlag T))
((eq (chr 32) Str)
(foreach x (reverse BlkLst)
(print x)) (textscr))
((snvalid Str)
(setq BlkLst (cons Str BlkLst)))
(t (princ "\n** Invalid Block Name **"))))
(if BlkLst
(progn
;; Get Directory
(setq *acad (vlax-get-acad-object)
Shell (vla-getInterfaceObject *acad "Shell.Application")
fDir (vlax-invoke-method Shell 'BrowseForFolder
(vla-get-HWND *acad) "Select Directory: " 0))
(if fDir
(progn
(setq Dir
(vlax-get-property
(vlax-get-property fDir 'Self) 'Path))
(if (not (eq "\\" (substr Dir (strlen Dir))))
(setq Dir (strcat Dir "\\")))
(if (< (atoi (setq acVer (substr (getvar "ACADVER") 1 2))) 16)
(setq acVer "") (setq acVer (strcat (chr 46) acVer)))
(setq dbx (vla-getInterfaceObject
*acad (strcat "ObjectDBX.AxDbDocument" acVer)))
(princ "\nProcessing...")
;; Iterate Drawings
[color=red] (foreach dwg (setq dwLst
(mapcar
(function
(lambda (x)
(strcat Dir x)))
(vl-directory-files Dir "*.dwg" 1)))
(vla-open dbx dwg)
(setq attlst (vl-bb-ref 'attlst))
(foreach blk BlkLst
(if (setq ss
(ssget "_X" (list
(cons 0 "INSERT")
(cons 2 blk)
(cons 66 1))))
(progn
(foreach att (mapcar
(function
(lambda (x)
(vlax-safearray->list
(vlax-variant-value
(vla-getAttributes x)))))
(mapcar 'vlax-ename->vla-object
(mapcar 'cadr (ssnamex ss))))
(setq attLst
(cons (list (vla-get-TagString att)
(vla-get-TextString att)) attLst)))
(setq attLst (cons blk attLst)))))
(setq attLst (cons dwg attLst))
(vl-bb-set 'attlst attlst)
(vla-saveas dbx dwg)
(princ (chr 46)))[/color]
(alert (vl-princ-to-string (vl-bb-ref 'attlst)))
(princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>")))
(princ "*Cancel*"))))
;; Garbage Collection
(ObjRel (list Shell dbx *acad))
(gc)
(princ))
;; Release Objects ~ Requires List of Variables
(defun ObjRel (lst)
(mapcar
(function
(lambda (x)
(if (and (eq (type x) 'VLA-OBJECT)
(not (vlax-object-released-p x)))
(vl-catch-all-apply
'vlax-release-object (list x))))) lst))
I have tried to set the "data-list" to the blackboard namespace and then collect this during with the opening of every drawing. - But at the end, when I check the value of the blackboard variable (using "alert"), it only contains the drawing filenames, and no attribute information.
This leads me to believe that the error is not in the blackboard entry, but in the selection set collection. Perhaps one cannot collect a selection set in another document space?
Thanks for any input - as I say, I am new to this branch of LISP if some of my questions seem naive.
Thanks,
Lee