MarcoW Posted December 20, 2010 Posted December 20, 2010 Hi all, Imagine me working on a drawing with an xref attached to it and I need to cut / copy something out of the actual drawing and paste it into the xref. At this moment I use ctrl+shift+c, select the basepoint and items, and open the xref so paste the thing as a block or not as a block. This works great as you can guess but how about making a lisp for it? During this process, I have had the idea of sending objects to an xref. Same procedure: select objects and basepoint. Then "send it to the xref, select xref, hit enter and ready. This is not a request, but just an idea I share. Maybe you like the idea and wanna try... Quote
Guest kruuger Posted December 20, 2010 Posted December 20, 2010 great idea Marco. i'm not a good lisp'er but maybe someone... kruuger Quote
pBe Posted December 20, 2010 Posted December 20, 2010 That would tremendously cut the time spent on editing the xref file. its a challege i'm willing to partake (NOT) Yeah, why not, I bet someone will...... i think i'll stick with "watch and learn" mode for now Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 I very much think it could be done - I'm halfway there with this - it would just need to be modified to cut out the drawing prompt and instead prompt for an XRef then retrieve the drawing path and finally perhaps delete the original objects. Quote
MarcoW Posted December 20, 2010 Author Posted December 20, 2010 I very much think it could be done - I'm halfway there with this - it would just need to be modified to cut out the drawing prompt and instead prompt for an XRef then retrieve the drawing path and finally perhaps delete the original objects. Wow, nice code Lee! Indeed it is almost what I meant. Did you have some kind of visions of me ? And for those who might be a little "suspicious"; I tested the code and of course it works! Lee, let me ask you NOT to modify the code (for now). Maybe I can do it with a little help, when I get the time... Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 (edited) Lee, let me ask you NOT to modify the code (for now). Maybe I can do it with a little help, when I get the time... Sorry dude, couldn't resist http://lee-mac.com/copytoxref.html There was a little more involved than that which I initially described to account for the relative positions of the objects to the XRef insert, and furthermore to account for scale/rotation/normal of the Xref. Lee Edited December 20, 2010 by Lee Mac Quote
MarcoW Posted December 20, 2010 Author Posted December 20, 2010 Lee, Check my addition to your the code. I had some help found with google: ;;-------------------=={ 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 }==--------------------;; ;; ;; ;; Applies a deep-clone copy to a list of objects ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; lst - List of Objects to Copy ;; ;; owner - Owner of Objects in List ;; ;; dest - Destination for Copied Objects ;; ;;------------------------------------------------------------;; ;; Returns: Array of Copied Objects ;; ;;------------------------------------------------------------;; (defun LM:CopyObjects ( lst owner dest ) ;; © Lee Mac 2010 (vla-CopyObjects owner (LM:ObjectVariant lst) dest) ) ;;-------------------=={ Object Variant }==-------------------;; ;; ;; ;; Creates a populated Object Variant ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; lst - list of VLA Objects to populate the Variant. ;; ;;------------------------------------------------------------;; ;; Returns: VLA Object Variant ;; ;;------------------------------------------------------------;; (defun LM:ObjectVariant ( lst ) ;; © Lee Mac 2010 (LM:SafearrayVariant vlax-vbobject lst) ) ;;------------------=={ Safearray Variant }==-----------------;; ;; ;; ;; Creates a populated Safearray Variant of a specified ;; ;; data type ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; datatype - variant type enum (eg vlax-vbDouble) ;; ;; data - list of static type data ;; ;;------------------------------------------------------------;; ;; Returns: VLA Variant Object of type specified ;; ;;------------------------------------------------------------;; (defun LM:SafearrayVariant ( datatype data ) ;; © Lee Mac 2010 (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray datatype (cons 0 (1- (length data))) ) data ) ) ) ;;-----------------=={ SelectionSet -> VLA }==----------------;; ;; ;; ;; Converts a SelectionSet to a list of VLA Objects ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; ss - Valid SelectionSet (Pickset) ;; ;;------------------------------------------------------------;; ;; Returns: List of VLA Objects ;; ;;------------------------------------------------------------;; (defun LM:ss->vla ( ss ) ;; © Lee Mac 2010 (if ss ( (lambda ( i / e l ) (while (setq e (ssname ss (setq i (1+ i)))) (setq l (cons (vlax-ename->vla-object e) l)) ) l ) -1 ) ) ) ;;-----------------------=={ Itemp }==------------------------;; ;; ;; ;; Retrieves the item with index 'item' if present in the ;; ;; specified collection, else nil ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; coll - the VLA Collection Object ;; ;; item - the index of the item to be retrieved ;; ;;------------------------------------------------------------;; ;; Returns: the VLA Object at the specified index, else nil ;; ;;------------------------------------------------------------;; (defun LM:Itemp ( coll item ) ;; © Lee Mac 2010 (if (not (vl-catch-all-error-p (setq item (vl-catch-all-apply (function vla-item) (list coll item) ) ) ) ) item ) ) [color=sienna][b]; My addition to retrieve the xref's path and name[/b][/color] [color=sienna][b](defun GetXrefPath ( / XrFile );XrPath)[/b][/color] [color=sienna][b] (setq XrFile (car (entsel "\nSelect external reference to copy the objects to: "))[/b][/color] [color=sienna][b]XrFile (vlax-ename->vla-object XrFile)[/b][/color] [color=sienna][b]XrPath (vla-get-path XrFile)[/b][/color] [color=sienna][b] );_setq[/b][/color] (princ) ) ;_defun ;|«Visual LISP© Format Options» (120 2 1 2 nil "Ende von " 100 9 0 0 0 T T nil T) ;*** DO NOT add text below the comment! ***|; It works but sometimes there is a problem with the UCS... I mean it copies but not to the right point. Maybe because Xrefs are inserted on different insertion points? What do you say so far? Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 What do you say so far? Not bad Marco! Seems like you understand the overall workings of the code quite well, your current modifications will copy the objects to the XRef, but the objects will be copied relative the WCS origin of the current drawing, not the origin of the XRef insert. I would also put all user input into the main program, and feed the XRef sub the selected object (makes it more of a generic sub). Quote
Glen1980 Posted December 20, 2010 Posted December 20, 2010 Forgive me for being dim, but isn't this already a command within xref edit in place? In LT2010 I can open the x-ref in place then use the icons that appear to make elements of the x-ref go onto the main drawing or elements of the main drawing become part of the x-ref. Unless I am misunderstanding what you want or is x-ref editing in place a problem with your office, I know when projects get going you always find a colleague in a drawing you want to use. Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 Forgive me for being dim, but isn't this already a command within xref edit in place? I was just up for the coding challenge Quote
Glen1980 Posted December 20, 2010 Posted December 20, 2010 You have to love a challenge! Makes life interesting Quote
Glen1980 Posted December 20, 2010 Posted December 20, 2010 Mine for today is getting my car home through the snow, whilst cursing not putting new tyres on it last week! Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 Mine for today is getting my car home through the snow, whilst cursing not putting new tyres on it last week! Good luck and safe driving Glen! Quote
Lee Mac Posted December 20, 2010 Posted December 20, 2010 Updated the code to allow for Relative Pathed XRefs Quote
MarcoW Posted December 20, 2010 Author Posted December 20, 2010 Forgive me for being dim, but isn't this already a command within xref edit in place? In LT2010 I can open the x-ref in place then use the icons that appear to make elements of the x-ref go onto the main drawing or elements of the main drawing become part of the x-ref. Unless I am misunderstanding what you want or is x-ref editing in place a problem with your office, I know when projects get going you always find a colleague in a drawing you want to use. Glen, you are absolutely right. I had no idea the command existed... to know: I use refedit a lot and never explored all the options. So first I say thank you for bringing up the idea. However, I cannot explain very well, but in some occasions you really need the "feel" to send stuff to an xref. The way as with the lisp from Lee, does the job better. Of course it is the same result but the procedure feels better. If I sound stupid: okay. Best regards, MarcoW. btw: Lee, it seems that I guessed right where my attempt would go wrong. The UCS thing... So thanks for taking time to explain. I must be hounest (is that english?) and say that not all of the code I understand. I am just not that lucky when it comes to time to spend on all I want in life. Quote
Glen1980 Posted December 20, 2010 Posted December 20, 2010 I use refedit a lot and never explored all the options. So first I say thank you for bringing up the idea. [/i] They only gave us LT paupers the X-ref edit in place option in 2010, I know full AutoCAD has had x-ref edit in place for years but I don't know when they put that little beauty of a command in there! BTW you English is way better than my Dutch (or is it Flemish? My geography classes left a lot to the imagination!) Quote
MarcoW Posted December 20, 2010 Author Posted December 20, 2010 (edited) BTW you English is way better than my Dutch Thanks. No Flemish is Belgium I believe. Lee did I tell you the code works great? Nice job, as always. Edited December 21, 2010 by MarcoW Just because... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.