Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy block definition from another drawing: Lisp Help

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
gccdaemon
1578 Views, 3 Replies

Copy block definition from another drawing: Lisp Help

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)
)

 

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
3 REPLIES 3
Message 2 of 4
hmsilva
in reply to: gccdaemon

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

EESignature

Message 3 of 4
gccdaemon
in reply to: hmsilva

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)
)

 

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 4 of 4
hmsilva
in reply to: gccdaemon


@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

 

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost