Ok .. this works ... but it does not have alot of error checking.
;;; IFF.LSP
;;; Copyright ©2005 by K.E. Blackie
;;;
;;; http://www.resourcecad.com
;;; kblackie@resourcecad.com
;;;
;;; AutoCAD 2000+ VisualLISP / ObjectDBX
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and that
;;; both that copyright notice and this permission notice appear in
;;; all supporting documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;
;;;
;;;
;;;
;;;----------------------------------------------------------------------------
;;; DESCRIPTION
;;;----------------------------------------------------------------------------
;;; C:IFF
;;;
;;; This program uses ObjectDBX in VisualLISP to import a block defined in any
;;; closed drawing file.
;;; There is limited error checking. It is presumed the user will modify this
;;; code to some degree to obtain the desired results.
;;;
;;;----------------------------------------------------------------------------
;;;----------------------------------------------------------------------------
;;; main function
(defun C:IFF (/ *acad* block_list block
blocks dbxDwg dcl_id done Dwgfn
ins_block
)
;; load the com object
(vl-load-com)
;; get the AutoCAD reference
(setq *acad* (vlax-get-acad-object))
;; save our dialog file (saves us from having more than one file to deploy)
(write_dialog)
;; get a drawing name
(setq Dwgfn (getfiled "Open File" "*.DWG" "DWG" 8))
;; initialize our insert block to the first element in the list
;; just in case the user does not click on the drop down control
(setq ins_block "0")
;; determine what version of AutoCAD we are running then open the appropriate
;; ObjectDBX interface version
;; We will register the ObjectDBX interface JUST IN CASE it already is not
;; Thanks goes to Kerry Brown at www.TheSwamp.org for putting the idea in my head
(if (= (atoi (getvar "AcadVer")) 16)
(progn
(setq DBXserver (findfile "AxDb16.dll"))
(startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
(setq dbxDwg
(vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16")
)
)
(progn
(setq DBXserver (findfile "AxDb15.dll"))
(startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
(setq dbxDwg
(vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument")
)
)
)
;; open the drawing
(vla-open dbxDwg Dwgfn)
;; grab the blocks collection
(setq blocks (vla-get-blocks dbxDwg))
;; for each block in the drawing .. grab it's name and make it into a list
;; filter for anonymous blocks, modelspace, paperspace and dimensions
(vlax-for block blocks
(if (/= "*" (substr (vlax-get-property block 'Name) 1 1))
(setq block_list
(append block_list
(list (vlax-get-property block 'Name))
)
)
)
)
;; load our dialog definition
(setq dcl_id (load_dialog "iff"))
;; our new dialog
(new_dialog "bl_filter" dcl_id)
;; start our list of blocks
(start_list "bl_names")
;; add them to the control
(mapcar 'add_list block_list)
;; end the list
(end_list)
;; define actions for our DCL controls
(action_tile "bl_names" "(setq ins_block $value)")
(action_tile "accept" "(done_dialog 1)")
;; start our dialog
(setq done (start_dialog))
;; if we closed the dialog with the insert button
(if (= done 1)
(progn
;; copy the block from the drawing header in the closed drawing
(vla-CopyObjects
dbxDwg
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
'(0 . 0)
)
(list
(vla-item
(vla-get-blocks dbxDwg)
(nth (atoi ins_block) block_list)
)
)
)
;; and put it in the current drawing
(vla-get-blocks
(vla-get-ActiveDocument *acad*)
)
)
)
)
;; release our ObjectDBX drawing
(vlax-release-object dbxDwg)
;; if we closed with the Insert button, then insert it
(if (= done 1)
(command "insert" (nth (atoi ins_block) block_list))
)
)
;;; dialog definition
(defun write_dialog (/ fn)
(if (setq fn (open "iff.dcl" "w"))
(progn
(write-line "bl_filter : dialog {" fn)
(write-line " aspect_ratio = 0;" fn)
(write-line " label = \"Block Insert Tool\";" fn)
(write-line " : popup_list {" fn)
(write-line " key = \"bl_names\";" fn)
(write-line " }" fn)
(write-line " : row {" fn)
(write-line " spacer;" fn)
(write-line " : ok_button {" fn)
(write-line " label = \"Insert\";" fn)
(write-line " width = 12;" fn)
(write-line " fixed_width = true;" fn)
(write-line " alignment = right;" fn)
(write-line " }" fn)
(write-line " : cancel_button {" fn)
(write-line " width = 12;" fn)
(write-line " fixed_width = true;" fn)
(write-line " alignment = left;" fn)
(write-line " }" fn)
(write-line " spacer;" fn)
(write-line " }" fn)
(write-line " }" fn)
)
)
(close fn)
)
Forgot to mention, this uses a technique employed by Tony Tanzilla to copy the block from one drawing to another.