李,
检查我对代码的添加。我在谷歌上找到了一些帮助:
-
- ;;-------------------=={ Copy to Drawing }==------------------;;
- ;; ;;
- ;; Enables a user to copy a SelectionSet of objects to a ;;
- ;; selected drawing. Layout on which objects reside will be ;;
- ;; created if non-existent. ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;;
- ;;------------------------------------------------------------;;
- (defun c:C2DWG nil (c:CopytoDrawing))
- (defun c:CopytoDrawing ( / *error* _StartUndo _EndUndo ac dbx doc dwgs dwg ss [b][color=sienna]XrPath[/color][/b])
- ;; © Lee Mac 2010
- (vl-load-com)
- (defun *error* ( msg )
- (LM:ReleaseObject dbx) (if doc (_EndUndo doc))
- (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
- (princ (strcat "\n** Error: " msg " **")))
- (princ)
- )
- (defun _StartUndo ( doc ) (_EndUndo doc)
- (vla-StartUndoMark doc)
- )
- (defun _EndUndo ( doc )
- (if (= 8 (logand 8 (getvar 'UNDOCTL)))
- (vla-EndUndoMark doc)
- )
- )
- (setq doc (vla-get-ActiveDocument (setq ac (vlax-get-acad-object))))
- (vlax-map-collection (vla-get-Documents ac)
- '(lambda ( d )
- (setq dwgs (cons (cons (strcase (vla-get-fullname d)) d) dwgs))
- )
- )
- (if (and (setq ss (ssget (list (cons 410 (setq tab (getvar 'CTAB))))))
- [b][color=sienna] ; Next, getfiled, will return the destination file including path.[/color][/b]
- [b][color=sienna] ; I turn this part off first.[/color][/b]
- [b][color=sienna] ; (setq dwg (getfiled "Select Drawing to Copy to" "" "dwg" 16))[/color][/b]
- [b][color=sienna] ; Now, how to retrieve the xref's name and path?[/color][/b]
- [b][color=sienna] ; See the SubFunction below, it returns the Xref name and path[/color][/b]
- [b][color=sienna] (GetXrefPath)[/color][/b]
- [b][color=sienna] ; Put the content of variable XrPath into the variable dwg[/color][/b]
- [b][color=sienna] (setq dwg XrPath)[/color][/b]
- [b][color=sienna] ; I remember: localise dwg and / or XrPath, see above in main function[/color][/b]
- );_and
- (progn
- (_StartUndo doc)
- (if (setq dbx (cond ( (cdr (assoc (strcase dwg) dwgs)) )
- ( (not (vl-catch-all-error-p
- (vl-catch-all-apply 'vla-open
- (list (setq dbx (LM:ObjectDBXDocument)) dwg)))) dbx)))
- (progn
- (LM:CopyObjects (LM:ss->vla ss) doc (vla-get-Block (cond ( (LM:Itemp (vla-get-layouts dbx) tab) )
- ( (vla-add (vla-get-layouts dbx) tab) ))))
- (vla-saveas dbx dwg)
- )
- )
- (_EndUndo doc)
- )
- )
- (LM:ReleaseObject dbx)
- [b][color=sienna] ; To make shure the right Xref is reloaded I use this, I have no better idea[/color][/b]
- [b][color=sienna] ; First what is NOT working, reload only the selected Xref:[/color][/b]
- [b][color=sienna] ; (vl-cmdf "_.xref" "_reload" dwg); WHY NOT ??[/color][/b]
- [b][color=sienna] ; This does work however:[/color][/b]
- [b][color=sienna] (vl-cmdf "_.xref" "_reload" "*")[/color][/b]
- [b][color=sienna] ; Takes a little more time, that shouldn't be[/color][/b]
- (princ)
- )
- ;;-----------------=={ ObjectDBX Document }==-----------------;;
- ;; ;;
- ;; Retrieves a version specific ObjectDBX Document object ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: - None - ;;
- ;;------------------------------------------------------------;;
- ;; Returns: VLA ObjectDBX Document object, else nil ;;
- ;;------------------------------------------------------------;;
- (defun LM:ObjectDBXDocument ( / acVer )
- ;; © Lee Mac 2010
- (vla-GetInterfaceObject (vlax-get-acad-object)
- (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
- "ObjectDBX.AxDbDocument"
- (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
- )
- )
- )
- ;;------------------=={ Release Object }==--------------------;;
- ;; ;;
- ;; Releases a VLA Object from memory via plentiful error ;;
- ;; trapping ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; obj - VLA Object to be released from memory ;;
- ;;------------------------------------------------------------;;
- ;; Returns: T if Object Released, else nil ;;
- ;;------------------------------------------------------------;;
- (defun LM:ReleaseObject ( obj ) (vl-load-com)
- ;; © Lee Mac 2010
- (and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj))
- (not
- (vl-catch-all-error-p
- (vl-catch-all-apply
- (function vlax-release-object) (list obj)
- )
- )
- )
- )
- )
- ;;--------------------=={ Copy Objects }==--------------------;;
- ;; ;;
|