你好,Renderman,
这对我来说很好:
- (defun c:test ( / dbx title master ) (vl-load-com)
- (setq title "C:\\my_titleblock.dwt"
- master "C:\\my_xref.dwg"
- )
-
- (if
- (and
- (setq dbx (LM:GetDocumentObject title))
- (setq master (findfile master))
- )
- (progn
- (vla-attachexternalreference (vla-get-modelspace dbx) master
- (vl-filename-base master) (vlax-3d-point '(0 0 0)) 1. 1. 1. 0. :vlax-true
- )
- (vl-catch-all-apply 'vla-saveas (list dbx "C:\\my_sheet.dwg"))
- (vl-catch-all-apply 'vlax-Release-Object (list dbx))
- )
- )
-
- (princ)
- )
- ;;-----------------=={ Get Document Object }==----------------;;
- ;; ;;
- ;; Retrieves a the VLA Document Object for the specified ;;
- ;; filename. Document Object may be present in the Documents ;;
- ;; collection, or obtained through ObjectDBX ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; filename - filename for which to retrieve document object ;;
- ;;------------------------------------------------------------;;
- ;; Returns: VLA Document Object, else nil ;;
- ;;------------------------------------------------------------;;
- (defun LM:GetDocumentObject ( filename / docs dbx ) (vl-load-com)
-
- (vlax-map-collection (vla-get-Documents (vlax-get-acad-object))
- (function
- (lambda ( doc )
- (setq docs
- (cons
- (cons (strcase (vla-get-fullname doc)) doc) docs
- )
- )
- )
- )
- )
- (cond
- ( (not (setq filename (findfile filename))) )
- ( (cdr (assoc (strcase filename) docs)) )
- ( (not
- (vl-catch-all-error-p
- (vl-catch-all-apply 'vla-open
- (list (setq dbx (LM:ObjectDBXDocument)) filename)
- )
- )
- )
- dbx
- )
- )
- )
- ;;-----------------=={ ObjectDBX Document }==-----------------;;
- ;; ;;
- ;; Retrieves a version specific ObjectDBX Document object ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: - None - ;;
- ;;------------------------------------------------------------;;
- ;; Returns: VLA ObjectDBX Document object, else nil ;;
- ;;------------------------------------------------------------;;
- (defun LM:ObjectDBXDocument ( / acVer )
- (vla-GetInterfaceObject (vlax-get-acad-object)
- (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
- "ObjectDBX.AxDbDocument"
- (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
- )
- )
- )
确保您具有直接写入C驱动器的权限。 |