(defun c:test()
;com init
(vl-load-com)
;call the directory common dialog by shell,then get the directory path
(setq objSH (vlax-create-object "Shell.Application"))
(setq dir (vlax-invoke-method objSH ’BrowseForFolder 0 "Select a forlder:" 1))
(setq msg (vl-catch-all-apply
’(lambda ()
(setq dir (vlax-get-property dir ’self))
(setq path (vlax-get-property dir ’path))
)
)
)
(if (vl-catch-all-error-p msg) (setq path nil))
(if path (setq dir (strcat path "\\")) (progn (princ "get directory path failure")(exit)))
;;get the list of all dwgfilename
(setq dwglist (vl-directory-files dir "*.dwg" 1))
;iter
(setq len (length dwglist))
(setq i -1)
(setq ybuf nil)
(repeat len
(setq dwgpath (strcat dir (nth (setq i (1+ i)) dwglist)))
;insert dwg by block
(command "_.insert" dwgpath (list 0 0 0) "" "" "")
(setq ent (entlast))
(vla-getboundingbox (vlax-ename-> vla-object ent) ’minpoint ’maxpoint)
(setq pt1 (vlax-safearray-> list minpoint)
pt2 (vlax-safearray-> list maxpoint)
;here,you can calc perfect coordinates for your insert dwg
x1 (car pt1)
y1 (cadr pt1)
y2 (cadr pt2)
h (- y2 y1)
)
(if (= nil ybuf)
(progn
(setq ybuf (+ y2 (* h 1.1)))
)
(progn
(setq pt2 (list x1 ybuf))
(setq ybuf (+ ybuf (* h 1.1)))
(command "_.move" ent "" pt1 pt2)