AutoCAD 2012, win7, VS2010 4.0-net
I'm thinking of converting an exising Autolisp routine that loops through a list of .dwg filenames, opening them in odbx,
and checking them to see if they contain a certain text string (see code below).
;;------------------;
;;10/13/05
;;Thanks to - T.Willey & Jeff Mishler
;;
(defun Chk4String (Doc String / flag)
(vl-catch-all-apply
'(lambda ()
(vlax-for i (vla-get-Layouts Doc)
(vlax-for Obj (vla-get-Block i)
(if (and
(or (= (vla-get-ObjectName Obj) "AcDbText")
(= (vla-get-ObjectName Obj) "AcDbMText")
)
(vl-string-search String (vla-get-TextString Obj))
)
(progn
(setq flag T)
(exit)
)
)
)
)
)
)
flag
)
;;------------------;
My knowledge of .net programming is still small and I'm trying to determine what would work best:
Should I use dbx code similar to what is found HERE
or could I obtain desired results as efficiently using the ReadDwg method?
I'll be running this in the AutoCAD MDIActive document.
Thoughts or comments appreciated.
Just need a shove in the right direction.
ObjectDBX (e.g., AxDbDocument) is mostly a wrapper around AcDbDatabase and some other functionality. The major issue is not which API you use, it is how many files you will try to open in a single AutoCAD session. There's a limit because no matter what you do, there will be incremental memory consumption with each processed file, that is not completely released until you exit the process. The details were explained by someone from ADN (forget who), but essentially, AutoCAD must allocate memory in chunks of a certain size, regardless of whether it actually needs that much memory or not, and hence, it can't always free it because some of it may be still be needed until the process is terminated.
So, if you use an in-process solution, you will have to terminate and restart AutoCAD after having processed a certain number of files, depending on their size. Of course, that makes an out-of-process solution easier because it can simply kill and restart AutoCAD as needed without having to kill itself in the process. The best of both worlds, is to use an out-of-process controller along with an in-process worker, where the out-of-process controller only controls the process of opening files, and closing and restarting AutoCAD while the heavy-lifting is done by the in-process component.
That arrangement also makes it easer to control multiple AcCoreConsole sessions as well.