nnutting Posted November 8, 2011 Share Posted November 8, 2011 Looking for help on the following routines: - Open xref from drawing by typing XO and then clicking on the reference. - Detach xref from drawing by typing XRX and then clicking on the reference. - Reload all xrefs in drawing by typing XRR Thank you in advance. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 8, 2011 Share Posted November 8, 2011 - open xref from drawing by typing xo and then clicking on the reference. xopen ..... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 8, 2011 Share Posted November 8, 2011 - Detach xref from drawing by typing XRX and then clicking on the reference. Quick one: (defun c:xrx ( / xn xr ) (while (progn (setvar 'ERRNO 0) (setq xr (car (entsel "\nSelect XRef to Detach: "))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type xr)) (if (not (and (eq "INSERT" (cdr (assoc 0 (entget xr)))) (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (setq xn (cdr (assoc 2 (entget xr))))))))) ) ) (princ "\nObject is not an XRef.") ) ) ) ) ) (if xr (vla-detach (vlax-ename->vla-object (cdr (assoc 330 (entget (tblobjname "BLOCK" xn))))))) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 8, 2011 Share Posted November 8, 2011 - Reload all xrefs in drawing by typing XRR (defun c:xrr nil (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (eq :vlax-true (vla-get-isxref block)) (vla-reload block)) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
nnutting Posted November 8, 2011 Author Share Posted November 8, 2011 Thanks Lee Mac... I can't find xopen in the program parameters...is there another way I can modify the key commands so I can use XO instead of typing the whole thing? Quote Link to comment Share on other sites More sharing options...
rkent Posted November 8, 2011 Share Posted November 8, 2011 Click on the xref, right click, open xref. Type XO and hit tab, hit enter. In the pgp set XO for xopen. Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 8, 2011 Share Posted November 8, 2011 few XRef macros from my startup file... ;; turn off all xref layers (defun c:XF (/) (command "_.-layer" "_off" "*|*" "") (princ)) ;; turn on all xref layers (defun c:XN (/) (command "_.-layer" "_on" "*|*" "") (princ)) ;UNLOAD ALL XREFS (defun c:xu (/) (command "_.-xref" "_UNLOAD" "*") (princ)) ;RELOAD ALL XREFS (defun c:XE (/) (command "_.-xref" "_RELOAD" "*" ) (princ)) Quote Link to comment Share on other sites More sharing options...
nnutting Posted November 8, 2011 Author Share Posted November 8, 2011 rkent... I'm running 2010...the right click on the xref worked in 2011 and 2012. My new company hasn't decided to make the jump to the new software. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 8, 2011 Share Posted November 8, 2011 Otherwise, just: (defun c:xo nil (command "_.xopen" pause) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 8, 2011 Share Posted November 8, 2011 Otherwise, just: (defun c:xo nil (command "_.xopen") (princ)) no need for the PAUSE. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 8, 2011 Share Posted November 8, 2011 no need for the PAUSE. Otherwise you get "Select Xref:" printed twice Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 8, 2011 Share Posted November 8, 2011 Otherwise you get "Select Xref:" printed twice probably right. I sometimes forget that not everyone keeps cmdecho set to 0. Quote Link to comment Share on other sites More sharing options...
Baber62 Posted October 31, 2012 Share Posted October 31, 2012 @ Lee Mac Excellent coding nice and neat fro detaching x-refs. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 31, 2012 Share Posted October 31, 2012 @ Lee Mac Excellent coding nice and neat fro detaching x-refs. Thank you Baber Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 2, 2012 Share Posted November 2, 2012 @ Lee Mac, Just one quick query on this one. I tried using the xref reload command, but got the following error: Command: xrr ; error: Automation Error. File access error I have done an etransmit of the file, which then places all the x-references into a respective folder. When I open the drawing, it opens but without the x-references in place, saying that the x-ref cannot be found. So when the routine is run it obviously cannot found the x-reference to reload. However, if I copy the x-references into the same folder as the drawing they are automatically loaded when the drawing is opened and I can unload and reload using the xrr routine. I am using the following routine to unload the x-reference rather than detaching it: (defun c:xru (/ tData XName);Identify/Unload Xref (defun *error* (msg) (princ " ") ) (while (setq tData (entget (car (entsel " Select Item to Test for Xref")))) (if (setq XName (cdr (assoc 2 tData))) (if (assoc 1 (tblsearch "BLOCK" XName)) (progn (command ".xref" "u" XName) (prompt (strcat " Xref " XName " unloaded" )) ) (princ " Block Selected - Try Again") );if (princ " Entity in Base Drawing - Try Again") );if );while (princ) ) Any advice on how to resolve this would be gratefully appreciated. The first rule of discovery is to have brains and good luck. The second rule of discovery is to sit tight and wait till you get a bright idea. G Polya Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 2, 2012 Share Posted November 2, 2012 However, if I copy the x-references into the same folder as the drawing they are automatically loaded when the drawing is opened and I can unload and reload using the xrr routine. When a drawing is opened in AutoCAD, the folder in which the drawing file resides is known as the 'working directory'. When AutoCAD searches for a file it first searches the working directory before searching the list of 'Support File Search Paths' as found under the 'Files' tab within the 'Options' menu. Hence, when the XRef files are placed in the working directory, they are found when AutoCAD attempts to locate the files; which leads me to ask: what is the path type for your XRefs? I am using the following routine to unload the x-reference rather than detaching it: (defun c:xru (/ tData XName);Identify/Unload Xref (defun *error* (msg) (princ " ") ) (while (setq tData (entget (car (entsel " Select Item to Test for Xref")))) (if (setq XName (cdr (assoc 2 tData))) (if (assoc 1 (tblsearch "BLOCK" XName)) (progn (command ".xref" "u" XName) (prompt (strcat " Xref " XName " unloaded" )) ) (princ " Block Selected - Try Again") );if (princ " Entity in Base Drawing - Try Again") );if );while (princ) ) Please note that your code will result in an error if the user fails to select an object, since the entget function will be passed a nil argument. However, this error will go undetected since you have redefined the *error* function to simply print a space without displaying the error message. Furthermore, since you have not localised the *error* symbol, you have redefined the in-built AutoCAD *error* handler, meaning that all error messages will go undetected for any AutoLISP program which does not define its own *error* function. Please read my tutorials on Error Handling and Localising Variables to better understand this practice. Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 2, 2012 Share Posted November 2, 2012 Hi Lee, The path for the x-references is as follows: E:\Southwark parking estates\Estates TMA and RTRA - INV_AREA 4\TQ Mastermap\TQ3374NW.dwg The drawing path is as follows: E:\Southwark parking estates\Estates TMA and RTRA - INV_AREA 4\Estates TMA and RTRA - INV_AREA 4.dwg Problem occurs when I try to reload the unloaded x-references using the xrr command. The first rule of discovery is to have brains and good luck. The second rule of discovery is to sit tight and wait till you get a bright idea. G Polya Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 2, 2012 Share Posted November 2, 2012 What is the XRef path type? i.e. Absolute / Relative / None? Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 2, 2012 Share Posted November 2, 2012 Lee, How do I find out whether the paths are absolute/relative/ none? At the moment they are on a memory stick so I would say that they are absolute, as they includes the local hard drive letter or the network server drive letter. The first rule of discovery is to have brains and good luck. The second rule of discovery is to sit tight and wait till you get a bright idea. G Polya Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 2, 2012 Share Posted November 2, 2012 How do I find out whether the paths are absolute/relative/ none? This can be determined from the XRef Palette (XREF at command-line) which lists all file references included in the drawing. The 'Saved Path' property of a file reference is the path used to determine the location of the source file for that reference. The nature of the 'Saved Path' (i.e. Full / Relative / None) is set when the XRef is inserted in the drawing and may be either a Full Path (an absolute path to the location of the XRef source file), a Relative Path (a path relative to the location of the drawing file in which the XRef is inserted), or None (i.e. no path is associated with the XRef and AutoCAD attempts to source the XRef file from the Support Path or Working Directory). At the moment they are on a memory stick so I would say that they are absolute, as they includes the local hard drive letter or the network server drive letter. The path type does not depend on the location of the XRef files, but how such files are referenced in the main drawing. Quote Link to comment Share on other sites More sharing options...
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.