本帖最后由 自贡黄明儒 于 2012-10-24 15:40 编辑
;;154.7 [功能] 复制非打开文件的块至本图
;;154.8 [功能] 复制非打开文件的特定块至本图
;;154.9 [功能] 复制特定文件的块至本图(不论打开或者非打开)
- ;;154.7 [功能] 复制非打开文件的块至本图
- ;;(Odbx-copyblocks 文件名)
- ;;(Odbx-copyblocks "D:\\DrawingA.dwg"),之后输入命令i,就可以看到DrawingA的块均在本图中了
- (defun Odbx-copyblocks (DwgName / DBXBLOCKS DBXDOC NUM)
- (setq dbxDoc (vla-GetInterfaceObject
- (vlax-get-acad-object)
- (GetObjectDBXVer)
- )
- )
- (vla-open dbxDoc DwgName) ;不能打开.dxf文件,返回nil
- (setq DBXBLOCKS (vla-get-blocks dbxDoc))
- (vlax-for BLK DBXBLOCKS
- (if (and (not (wcmatch (substr (vla-get-name BLK) 1 1) "`*"))
- (= (vla-get-isxref BLK) :vlax-false)
- ) ;去除系统块、匿名块和参照类对象
- (setq namelst (append namelst (list (vla-get-name BLK))))
- )
- )
- (foreach name namelst
- (setq num (vla-item DBXBLOCKS name))
- (vla-copyobjects
- dbxDoc
- (vlax-safearray-fill
- (vlax-make-safearray vlax-vbobject '(0 . 0))
- (list num)
- )
- (vla-get-modelspace
- (vla-get-activedocument (vlax-get-acad-object))
- )
- )
- )
- (if dbxDoc
- (vlax-release-object dbxDoc)
- )
- )
;;154.8 [功能] 复制非打开文件的特定块至本图
;;示例(CopyBlock "D:\\DrawingA.dwg" "ccd1"),之后输入命令i,就可以看到DrawingA的"ccd1"块在本图中了
;; COPYBLOCK.LSP Copyright ?999 Tony Tanzillo
;; http://www.caddzone.com
;; tony.tanzillo@caddzone.com
(defun CopyBlock (DwgName BlkName / *ACAD* BLOCKS DBXDOC NUM)
(setq *acad* (vlax-get-acad-object))
(setq blocks (vla-get-blocks (vla-get-ActiveDocument *acad*)))
(setq dbxDoc (vla-GetInterfaceObject *acad* (GetObjectDBXVer)))
(vla-open dbxDoc DwgName)
(setq num (vla-item (vla-get-blocks dbxDoc) BlkName))
(vla-CopyObjects
dbxDoc
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
'(0 . 0)
)
(list num)
)
blocks
)
(vlax-release-object dbxDoc)
(vla-item blocks BlkName)
)
;;154.9 [功能] 复制特定文件的块至本图(不论打开或者非打开)
;;本程序将选择一个文件,然后将其下的块均拷贝到本图中,用命令i就可以插入这些块了
(defun B2CurDrawing (/ *ACAD* *DOC* *DOCS* FNAME FULLNAME LST)
(defun Open-copyblocks (fname / BLOCKS DOC DOCBLOCKS NAMELST NUM)
(setq blocks (vla-get-blocks *DOC*))
(setq Doc (vla-item *DOCS*
(strcat (vl-filename-base fname)
(vl-filename-extension fname)
)
)
)
(setq DocBLOCKS (vla-get-blocks Doc))
(vlax-for BLK DocBLOCKS
(if (and (not (wcmatch (substr (vla-get-name BLK) 1 1) "`*"))
(= (vla-get-isxref BLK) :vlax-false)
) ;去除系统块、匿名块和参照类对象
(setq namelst (append namelst (list (vla-get-name BLK))))
)
)
(foreach name namelst
(setq num (vla-item DocBLOCKS name))
(vla-CopyObjects
Doc
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
'(0 . 0)
)
(list num)
)
blocks
)
)
(vlax-release-object doc)
)
(setq *ACAD* (vlax-get-acad-object)
*DOC* (vla-get-ActiveDocument *acad*)
*DOCS* (vla-get-Documents *ACAD*)
)
(setq fullname (vla-get-fullname *DOC*))
;;打开文件列表
(vlax-for doc *DOCS*
(setq
lst (cons (if (/= (setq fname (vla-get-fullname doc)) "")
fname
(vla-get-name doc)
)
lst
)
)
)
(setq fname (getfiled "选择DWG文件"
(strcat (vl-filename-directory fullname) "\\")
"DWG"
0
)
)
(cond ((and fname (member fname lst) (not (equal fullname fname)))
(Open-copyblocks fname)
)
((and fname (not (member fname lst)))
(Odbx-copyblocks fname)
)
(T nil)
)
(princ)
) |