Need help with this. Not sure what's going wrong. Looked for several variations and keep getting this error message:
; error: Automation Error. Problem in loading application
(defun GETBLOCK (DWG BLK / DBX) (vl-load-com) (setq DBX (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")) (vla-open DBX DWG) (vla-CopyObjects DBX (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks DBX) BLK))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object DBX) )
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
HI Andrew,
try
(if (< (atoi (substr (getvar "ACADVER") 1 2)) 16) (setq DBX (vlax-create-object "ObjectDBX.AxDbDocument")) (setq DBX (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)) ) ) )
Hope this helps,
Henrique
Yah, it's working now. A few quick questions since I'm still learning and all. How does the ACADVER variable play into this? Is it related to the object creation in the current drawing? If so why would it matter what version?
Working Code:
(defun GETBLOCK (DWG BLK / DBX) (vl-load-com) (if (< (atoi (substr (getvar "ACADVER") 1 2) ) 16) (setq DBX (vlax-create-object "ObjectDBX.AxDbDocument")) (setq DBX (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)))) ) (vla-open DBX DWG) (vla-CopyObjects DBX (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks DBX) BLK))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object DBX) )
@gccdaemon wrote:
Yah, it's working now. A few quick questions since I'm still learning and all. How does the ACADVER variable play into this? Is it related to the object creation in the current drawing? If so why would it matter what version?
Andrew,
Prior to AC2004, "ObjectDBX.AxDbDocument"
after AC2004, (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))
I also would suggest, to test first 'dwg' with 'findfile', and test the 'blk' existence at block collection with something like this
(if (not (vl-catch-all-error-p (vl-catch-all-apply (function (lambda () (setq blkdbx (vla-item (vla-get-blocks dbx) blk)))) ) ) ) (vla-copyobjects dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list blkdbx) ) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ) )
Hope this helps,
Henrique