Jump to content

XREF Lisp routines


nnutting

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • Baber62

    6

  • alanjt

    3

  • nnutting

    3

Top Posters In This Topic

Posted Images

- 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)

Link to comment
Share on other sites

- 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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 11 months later...

@ 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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...