Using XREFs and XREF Best Practice

XREFs can be an extremely helpful tool at your disposal when used well. However when used badly they can be a nightmare. In this article I am going to go through how to use XREFs and talk about some best practice tips to get the most out of your XREFs. Also I’ll talk about some common pit-falls that often cause problems.

What is an XREF?

If it wasn’t already obvious to you, XREF stands for external reference. As such, these are drawing files that are used as external references in our drawing. Other names for XREFs include references, overlays, attachments and model files. No matter what the name, the concept is the same. The external file is inserted into the current drawing as a reference. If you want to edit the geometry of the XREF, you’ll need to open the referenced file and edit that.

Basic Usage

We can insert an XREF by simply entering XREF into the command line. This brings up the the External References dialog box. In the top left there is a button for attaching a DWG file. Click this button, and you will be prompted to select a DWG file to insert. The insertion point for the XREF will always use the coordinate 0,0 in the XREF as the base-point in a similar fashion to how blocks work.

The External References dialog lists the currently loaded XREFs and displays details for each. Here is a good place to look to find any problems with your XREFs, such as XREF paths that might have changed. You can update the XREF paths from here by overwriting the “found at” path, or by selecting the ellipsis (…) in this field and browsing to the drawing. If you seem to be unable to edit this, it is likely that the reference you are trying to edit is a nested reference. This means that the drawing is actually an XREF within another drawing, and has not been directly referenced to this drawing. In other words, it is an XREF within an XREF. If this is the case you’ll need to edit the path within the first XREF, and then refresh that XREF within the current drawing.

While the External References dialog can be convenient, for simply inserting an XREF you do not need to open this dialog. Using the XATTACH command, you can invoke the command that would be used by clicking the DWG button on the XREF dialog.

Best Practice

What to use XREFs for

XREFs should be used for content that could potentially be displayed on many drawings. Having multiple copies of the same thing is just a pain to deal with. Ok, you can copy easily enough from one drawing to the other, but you have to remember to do that every single time you make any change to either drawing. The solution is to use an XREF. Put all the information in the one drawing and insert that XREF into all the drawings that require it. Essentially, XREFs can become a kind of external modelspace for your drawings, saved in a central location. You can also logically separate aspects of the model so that each XREF has its own distinct purpose. This is a great way to add some structure to you drawings, and minimise any headaches you might face later with discrepancies between drawings.

Breaking your modelspace down into smaller XREFs is also a great way to reduce file size. I work under the premise that the bigger the drawing file size, the higher the chance that it’ll crash my PC. As such I try to keep individual drawings to below 5mb. Sometimes this is not practical, but mostly it is.

Also, be careful of surveys and other mapping information such as Ordnance Survey maps. While these are of course essential, avoid putting these directly into your drawings like the plague. These should ALWAYS be an XREF, unless you actually want AutoCAD® to crash 🙂

Attachments vs Overlays

XREFs can be inserted as two different types; an attachment or an overlay. While both may appear to achieve the same thing, there is a subtle difference between them. If you insert an XREF as an attachment, this means that any other drawings that XREF the current drawing will also show the nested XREF as well. For example, Model.dwg contains the XREF Outline.dwg as an attachment. If Drawing1.dwg then XREFs Model.dwg in, Outline.dwg will also be shown as a part of Model.dwg.

Conversely, overlays allow you to insert as many XREFs as you want, but prevents them from being nested. So in the example above, if Outline.dwg were inserted as an overlay, it would not be shown when Model.dwg is XREFed into Drawing1.dwg.

So which do you use? Well, like most things it depends what you’re doing. Generally speaking the preferred default option is to use overlays, because this prevents the possibility of having a reference loop, and is generally the more lightweight option. However, if you have much to gain from having XREFs that contain other XREFs, clearly an attachment is the way to go.

Where should XREFs be saved?

This is a good question – they have to go somewhere, and having them scattered all over the place so that you don’t know what’s what is not good at all. Generally speaking, I create a folder called xrefs, and put them all in there. I sort of consider the xrefs folder as the modelspace of all my drawings, and I treat it accordingly.

I have the luxury of working on projects that aren’t massive, so if you’re working on huge projects you’ll certainly need some other structure to accommodate the scope of the project. It would be no good having hundreds and hundreds of drawing files all saved in one folder named xrefs. For this, you’d probably have to set up zones, and subcategorise your xrefs by zone. This will have to be done on a project by project basis, and agreed with the others working on the project before starting.

Pit Falls

I’m going to kick off the pitfalls with VISRETAIN, a system variable that has been the bane of many a AutoCAD® user. It can easily catch you out as well. VISRETAIN controls how layers within XREFs behave. With VISRETAIN set to 1, the layer state of XREFs are remembered. So when you make some intricate changes to your XREF layers to ensure it plots a certain colour for example, this will be remembered. Set VISRETAIN to 0 and it’s another story – you’ll close the drawing, the layer changes you made will be lost, and you’ll have no idea it happened until you open the drawing again, and (maybe) spot the mistake. If you never ever want this to be an issue again, put this in acaddoc.lsp, which ensures VISRETAIN is set to 1 each time a drawing is opened:

(setvar “VISRETAIN” 1)

Next, I’ll talk about broken XREFs. A broken XREF is what we call an XREF with a path that no longer resolves to the .DWG file that it originally pointed to, and the file cannot be found. This is usually the result of an element of the path being renamed, such as the folder or the .DWG file itself. As noted earlier, you can update the path for the XREF from the XREF dialog, and modifying the “found at” path.

An additional problem can be to do with drive paths. Say you have an XREF that resides in W:\CAD\Projects\xrefs, but you also have a Z drive mapped such that Z:\Projects\xrefs refers to the same folder. If the XREF was originally loaded using the W:\CAD\Projects\xrefs path, then AutoCAD® usually expects the drawing to be on the W drive. This can be a temperamental issue, but I have often found that AutoCAD® will prevent you from re-loading an XREF from what appears to be another drive.

If you or someone else has renamed a folder, you’ll notice that many, if not all of your XREFs will have a broken path. Then you’re faced with the somewhat daunting task of updating all the XREF paths in your whole drawing set… For this, look into using the Reference Manager tool provided with AutoCAD® – its really useful, but I’ll save the details for another post.

The final problem is that with great power comes great responsibility! Although it is great to be able to update all your drawings in one go, equally you can screw the whole set up just as easily. BE CAREFUL. And regularly take a backup of your XREFs folder so that if you make a huge mistake, you can roll back to a previous version.


So there we go – XREFs. Use them, and use them wisely.


P.S. Don’t forget to subscribe below – I’m nearly at 200 subscribers!

The BURST Command

I had another little gem come out of the woodwork today, it’s an express-tool called BURST.

For years I’d been annoyed that exploding a block with attributes would reveal the attributes within the block rather than the values they were set to.

The BURST command solves this problem, and explodes the block, and converts all the attributes to text for you. Simply enter BURST to the command line, and select the block you want to explode.

Really handy when you need it.


How to use acad.lsp and acaddoc.lsp

Lisp is a very useful part of the AutoCAD® application, and one of the first things its good for you to know is how acad.lsp and acaddoc.lsp work. These two lisp files are automatically executed when certain conditions occur in AutoCAD.


Firstly, acad.lsp is by default executed when AutoCAD® first boots up. Therefore, this will run once only. Because of this it is a great place to put startup procedures, or things that you want to do to initialise AutoCAD®. For example, I have mapped commands to various key combinations under my left hand, including SS, DD and DA. The problem is, these are existing built in commands to AutoCAD®. The solution for me was to use the UNDEFINE command to remove the default commands from AutoCAD®, which would then allow my own customisations in acad.pgp to take priority. And acad.lsp is a great place to run these commands, like so:

(command “undefine” “ss”)
(command “undefine” “dd”)
(command “undefine” “ad”)

For those new to lisp, the lisp command at work here is “command”, which basically allows you to invoke any AutoCAD® command from lisp. The text provided in quotes will be executed as if you had entered them into the AutoCAD® command line.


So how does acaddoc.lsp differ? As the name suggests, this has something to do with documents. In fact this lisp file is run every time a document is opened. Therefore this is the perfect place to do anything that is specific to the drawing you are working on. For example, I have a few system variables that I like to be set a certain way. Annoyingly they are drawing specific, but using acaddoc.lsp we can set them to whatever we want when the drawing is opened:

; SKETCH produces polylines
(setvar “SKPOLY” 1)
; suppress “Would you like to convert to a polyline prompt”
(setvar “PEDITACCEPT” 1)
; set linetypes to be continuous on polylines
(setvar “PLINEGEN” 1)

Here are a few. For those learning lisp, the”setvar” lisp command tells AutoCAD® to set the value of a system variable (pretty obvious really!). Again, the arguments passed to it will have to correspond with how you’d enter them into the command line normally.

Where to save acad.lsp and acaddoc.lsp

The location of where to save acad.lsp or acaddoc.lsp depends on what you want to achieve, but it will only be loaded if it is found in one of your support paths, as specified in Options > Files > Support File Search Path. In the beginning, I assumed you could have many of these files in multiple support paths, but AutoCAD® will only load one. If there are many, AutoCAD® will load the first one that it finds in the order specified in your support paths. Support paths higher on the list will be searched before lower ones.

If you are working in a team that use several of the same lisp functions, a good idea is to place acad.lsp and acaddoc.lsp in some networked location, and add that location to you list of support paths. This is a much more manageable way, rather than trying to keep multiple files up to date on many computers. In order for these to run of course, it will have to be the first acad.lsp or acaddoc.lsp file that it finds, so you may have to rename or delete old versions of acad.lsp/acaddoc.lsp that already exist in local support paths.

So hopefully this has helped to understand acad.lsp and acaddoc.lsp. It’s pretty simple really, but knowing that little bit of extra detail can help to get things working the way that you want.

As always, I’d like to encourage newcomers to subscribe below, and you’ll get an email every time I write something new. If I don’t write anything, then you’ll get no email!


The XLine Command and Creating Levels in your Drawing

With the Ortho Mode and Polar Tracking at your disposal, you may be tempted to completely ignore the concept of construction lines. But I certainly still use them, as they are actually really useful for specifying a logical concept in your drawing – for instance, a level.

Basic usage of the XLINE command is simple. Enter XLINE at the command line, followed by two points that define an origin and a direction. There are additional options at the command prompt – H and V constrain the construction line to the Horizontal and Vertical directions respectively. A forces the xline to be drawn at a specific angle, which can also sometimes be useful. The O option is basically the same as the offset command, but forces the new line to be an XLINE rather than imitating whatever you selected. The B option I’ve never actually used before, but this option draws the XLINE that bisects, or is the midpoint of the angle you enclose with three points.

I mentioned that XLINEs are useful for levels, but when drawing a section or elevation with known levels, it can sometimes be clumsy inputting the elevations. For this reason, I always draw sections and elevations at their real world level in the Y direction.



Here for example, we are showing a level of 0, and 4 above some datum. Here it would be good practice to ensure that the level we have shown on the drawing is actually the level in the Y axis of the drawing. That way, we can be more certain that the drawing is correct. It also makes checking very easy using the ID command, by simply looking at whatever it says for the Y axis, and comparing with what we know it should be.

But there still is the problem of inputting the levels in a quick and elegant way. Up until recently, I had been using an XLINE drawn horizontally at a level of 0, and then offsetting upwards the amount required. This works, but it’s not the quickest way. A slight improvement is to invoke the XLINE command, press H for Horizontal, and then input a coordinate manually, using 0 (or any other number) for the X coordinate, and the desired level for the Y coordinate. This works, but still (for me) isn’t as elegant as it could be.

So instead, I decided to create a neat little lisp, for getting an XLINE at a specific level on the drawing:


This simple command asks you for a level, and an XLINE appears in your drawing at that level. It also scales what you enter by a factor of 1000, so that levels displayed in metres are instantly converted to millimetres. I’d suggest having a look at the lisp code, as it is really quite a good example of how a little bit of lisp can get a job done. It also gives you the opportunity to optimise the code for whatever units you are using.

All for now,



Trimming a Segment of a Polyline

Here’s a little tip that might be obvious to some, if not most of you. But for anyone that doesn’t know this, it can be useful to know.

When using the trim command, you tend to specify geometry to trim lines back to. Of course this is no different with polylines, and you can of course use polylines to trim other geometry back to. But you may not know that you can actually trim a polyline back to itself, even when it doesn’t intersect itself. For example, you may have a polyline that looks like below:



Lets say you want to trim away the whole horizontal portion of the polyline. A lot of people would invoke the TRIM command, hit spacebar or enter to select trimming back to everything, and trim away the individual parts of the polyline (the coloured parts below):


Ok, I admit that this gets the job done. But on a more complex polyline, with more information in the drawing this will take longer. AutoCAD® has to compare the point you picked with all other objects in the drawing to detect places to trim back to. In severe cases where the drawing is very busy, you could be faced with a crash situation, as the computer calculates all the possible lines you might want to trim back to.

For this reason, I think it is best to always tell AutoCAD® exactly what you want to do. Doing so minimises the complexity of the task, thus minimising the chance of AutoCAD® crashing or hanging.

So in this case, what I would do is invoke the TRIM command, select the polyline, and then pick the horizontal section. This is the most clear instruction to AutoCAD®. AutoCAD® knows to ignore any geometry other than that selected, which makes it very easy to know what you want to achieve. AutoCAD® will trim back to the next found vertices of the polyline:


So there we go – not exactly the most revolutionary tip in the world, but it could save you some time and gives a clearer instruction to AutoCAD®, thereby reducing the calculation overhead and crash chance.

That’s all for today.


P.S. As always, I’d like to remind any new readers to subscribe below – its just an email, whenever I’ve written a new article.



I was setting up a dynamic block yesterday, and I wanted to specify a default position for all the movable parts, but I also wanted to have the option to reset the block to the default position after I’d moved stuff around. I started thinking along the lines of using visibility states in my block, but it wasn’t really what I wanted – ideally I’d like a command that resets a dynamic block to its original unmodified position.

So imagine my happiness to discover the RESETBLOCK command! It does exactly what you would expect – resets a dynamic block to its original state. Perfect, and worthy of sharing.

Hope this helps someone.

And by the way – if you haven’t already, have a proper play with dynamic blocks. They can be extremely useful, and pretty darn cool too!


P.S. If you subscribe below I will pay you some money.

P.P.S. Not really. But still subscribe please 🙂


The SKETCH Command – Drawing Freehand in AutoCAD

The SKETCH command is one of those little known commands, but it really is a great command when you have the opportunity for some artistic license in your AutoCAD® drawings. You know when you have an irregular line to draw that represents existing ground level, or some other arbitrary uneven surface? For this kind of thing, it’s a great command to use. SKETCH allows you to draw geometry, freehand, in AutoCAD®. You simple click a start point, move the mouse in any direction, and the path your mouse follows will be drawn into AutoCAD®. You’ll probably end up thinking you’re in MS Paint, and I defy anyone to not scribble all over the screen when testing it out… !

Normal Usage

To begin the command, input SKETCH into the command line. You will be prompted for a start point, or [Type/Increment/toLerance]. If you want to just get stuck in, pick a point, do your scribble (heh), and then pick your final point. This will terminate that line, but the command will continue. You can then pick another point and repeat the process. If you prefer, you can actually click and drag to draw one sketch, which does make it somewhat easier to draw one sketch after another. To complete the command, press spacebar or enter or whatever method you usually use to complete a command. It should be noted that if you exit the command at this point (i.e. press escape), your lines will be deleted. This one trips me up quite often, because this is different to how the PLINE command works for example.

Command Options

After invoking the SKETCH command you are prompted for a point or [Type/Increment/toLerance]. These settings are very useful for ensuring the SKETCH command behaves in the way that we want.

Pressing T for the type option allows you to change what is created with your sketch. By default, this is set to draw lines, which frankly speaking I think is just stupid. If you want to fill up your drawing with tiny little individual lines then this is the perfect option for you… I tend to use polylines personally, as I like to keep my geometry logically grouped depending on what they are. So if it represents existing ground level for example, that’s one logical entity, therefore it should be one actual entity in AutoCAD®. The other option for the type is to draw splines. I have personally not used this one much (as I’m not a fan of splines in general), but it’s there if you want to use it.

Pressing I for the increment option allows you to specify a minimum length of a segment in your sketch. This is really useful where you want a certain level of coarseness in your sketch, which I often like to see. It is also great for reducing the total number of segments you actually produce with this command.

Finally, pressing L for the tolerance option refers only to splined sketches – it controls how closely a spline follows the path drawn.

System Variables

The SKPOLY system variable is where your setting for the type is actually saved. This system variable is saved in the drawing, which can be somewhat annoying if you’d prefer it was always set to polyline by default. But there is of course a work around as always.

As with all drawing-saved system variables such as this, you can edit acaddoc.lsp so that each time you open a drawing, your system variables are set automatically. Input the following into your acaddoc.lsp file, found in your support directory:

(setvar “SKPOLY” 1)

This will ensure that the SKETCH command will be set up to drawing polylines in all drawings.

The SKETCHINC and SKTOLERANCE system variables do the same for the increment and tolerance options respectively. You can of course edit the lisp code above for those two system variables too, should you need to.

Final Notes

As you can imagine, the SKETCH command can potentially add a lot of geometry to your drawing. Be mindful of how much information you’re putting in, and how much is actually required. If you’re just drawing an indicative line for example, it hardly needs to be drawn with the increment set to 0.0000001… and doing so will add significant bloat to your drawing. I tend to ensure that there is a slight pause between each point when drawing the line – that way I am actually thinking about the points I’m adding to the line, which means there can’t be (much) more than required.

Hope this helps you all, and happy doodling!


P.s. for all you newcomers, please subscribe below!