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.

Will

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

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:

level.lsp

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,

Will

 

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.

Will

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.

 

Shaped Viewports

Here’s a quick tip for today.

No doubt you’re aware that you can have custom shaped viewports – select a viewport, right click, and choose the option to clip the viewport based on a bounding object such as a polyline.

While this can be useful, be careful on drawings that contain a lot of information. There’s a reason rectangular ones are the default. Rectangles are easy for a computer to deal with. They have a set width and height, and it is easy to know what should and should not be displayed through the viewport.

Polygonal viewports are different – your computer has to mathematically determine what should and should not be displayed, and that is much more difficult to figure out for odd-shaped viewports. Incidentally, if you’re interested in how this might be done take a look at my ray casting algorithm for AutoCAD.

Therefore, where possible, try to stick to rectangular ones. That doesn’t mean use rectangular ones at all costs, just be aware that if you have a busy drawing (like a survey) and view it through a polygonal viewport, you’re in for some rendering lag!

Hope this helps,

Will

Layer Freeze/Thaw vs On/Off

There are two ways to change the visibility of layers – turning it off using the little light-bulb, and freezing it using the little snowflake. Many times I’ve been asked, “What’s the difference between freezing a layer and turning it off?”. For years I had no idea what the difference was, or if in fact there was a difference at all! I simply got in the habit of just using the ON/OFF setting, but having found out what the subtle difference between them is, I’ve changed over to mainly freezing layers because it usually more accurately fits my intent.

Turning a layer off using the ON/OFF setting makes the objects on that layer hidden, but these object will still be considered part of the drawing. For example, you may have noticed that objects that have been turned off are still selectable in the drawing. Selecting it directly on screen of course still isn’t possible, as you’ve nothing to click on. But other ways of selecting objects will still pick it up – try a SELECTALL for example, and your objects that are turned off will be selected.

Frozen layers on the other hand are completely off. They are not considered part of the drawing at all, and are therefore not selectable.

Due to the different ways that AutoCAD® handles these layer properties, each carries a different overhead. Objects on an off layer are basically just as usable in a drawing as if that layer was on, and therefore AutoCAD® has to still prepare the objects in the same way as if they were on. For example, when AutoCAD® regens, these objects will be regenerated too. Frozen layers are meant to be completely ignored, and therefore carry no such overhead.

There are some other interesting consequences of these two layer visibility toggles. ZOOM EXTENTS for example will zoom to the extent of objects in the drawing. As layers that are turned off are still considered part of the drawing, they will affect zoom extents. Frozen layers on the other hand will not.

Finally, there are some differences to how visibility is affected within blocks. Lets say I have a block with objects on layer BLUE and GREEN, and the block itself is inserted on layer RED. Toggling the visibility of BLUE and GREEN works as expected for both methods. However, there is a difference when toggling the insertion layer of the block. If the layer RED is turned off using the ON/OFF toggle, the objects on BLUE and GREEN will still be visible. However, if RED is frozen, all of the objects in the block will be hidden, regardless of their layer.

But why have these two different methods? It is less of an issue now, but historically these were added when regenerating a drawing took a lot longer. Therefore it was helpful to have the option to turn things off without the drawing requiring regeneration every time. Thus, the ON/OFF toggle was helpful for showing what you want, but keeping them available to be displayed quickly.

Hopefully you found this post both interesting and useful. However, I’m a realist – if it was only one of those adjectives, that still aint bad! But if you have your own adjective for describing this post that you’d like to add, please feel free to submit a comment below! 🙂

And on the rare occasion that you did find this post interesting or useful, or indeed both, I encourage you to join the literally tens of others that have subscribed.

Thats all for today,

Will

Funny Text

This probably sounds like I’m going to start talking about the latest joke book, but that’s not what I mean by Funny Text…… I’m talking about subscript, superscript and special characters.

The two ways I usually use are – Alt Codes and using the stack options in the MText editor. 

Alt Codes

  1. Go to Start>All Programs>Accessories>System Tools>Character Map
  2. Have a look around for the symbol you want, and select it.
  3. In the bottom right you’ll see something like Alt+0178.
  4. Go back to where you want to insert the symbol and hold down the Alt key and type 0178. This will insert the special character.

 Stacking

  1. If you want to have superscript, write what you want to appear as superscript followed by the ^ character, then followed by as many spaces as the number of characters you want to be superscript. In the example below I only want one character to be superscript (²), so I have included a single space after the ^ character.
  2. Select the text, including the trailing spaces (as below), and click the stack button circled in red.

For subscript, the text and spaces should be the other way around – so in this example, to create a subscript 2, you would use the text ” ^2″. You can also have a combination of both subscript and superscript, but using text instead of spaces on the opposite site. You can exchange the ^ character for the / character, and this will include a line between the subscript and superscript to signify a fraction.

I hope this helps!

Will

Ortho Mode vs. Polar Tracking

Ortho mode and polar tracking are two methods of constraining user input to an axis. You’ve probably become accustomed to using one of them, but if you think they are the same, you may want to look again. Of course, I am talking about these options at the bottom of AutoCAD:

Ortho Mode

Ortho mode constrains user input to horizontal and vertical input. That is, if you draw a line, it will draw it from the first point in either the horizontal or vertical direction. Of course if you snap to an object this will override ortho mode, but you can still use other objects as a reference by using object snap tracking. With object snap tracking, hovering over a snap point will cause a small temporary marker to appear, and you can then use the horizontal and vertical axes of that point as a reference. But, I digress… with ortho mode enabled, you are constrained horizontally and vertically, which is often complemented by the use of object tracking.

Polar Tracking

Polar tracking does not force the constraint to either the horizontal or vertical axis in the same way that ortho mode does. With polar tracking, you are only constrained to the axis if you are in close proximity to the axis, in a similar way to how you will only snap to objects you hover over. During a command if you are hovering over the horizontal or vertical axis, polar tracking will constrain you to that axis. In my opinion, this is the better way, because there is very rarely the need to turn this option off. If you want to draw vertically, hover in the vertical direction. If you want to draw horizontally, hover in the horizontal direction. If you want to draw randomly, draw in a random direction! I believe that polar tracking gives the user a bit more freedom to choose, without the need to turn it on/off.

There is another reason I particularly enjoy polar tracking – a technique I’ve called polar tracking 45. And, this is simply setting up your polar tracking to include tracking in 45° increments.

What’s the point of that you say? You rarely draw things with 45° angles so you hardly see this being useful…

Fair point, but what IS useful, is bearing in mind a few properties of lines drawn at 45°. For example, if you draw horizontally from 45° line, whatever distance you draw will be the exact same distance vertically:

This can be handy in situations where you want to maintain some known distance. Also, having a 45° can work wonders in combination with the mirror command – you’ll be inventing new and wonderful ways to draw things all day:

You’d have never guessed that this cross, comprised of only right angles, was actually drawn using 45° angles. This is only an arbitrary example, but there are a surprising amount of practical uses you will find when working. Try it out for a day – you’ll like it!

So that’s my piece on ortho mode vs polar tracking – in my opinion, polar is the way to go.

If you found this post useful, please do subscribe – I’m always trying to add new tips like this. So if you liked this, you should like what’s to come. Also, I’ve decided that it could be of benefit to this site to add the work of others on here, subject to suitability of course – so, if you have written a manual about something CAD related and want to become a published author (lol), get in touch! I’d love to hear what you have to say.

Thanks for your ongoing support.

Will

The Modelspace or Paperspace Argument

I’ve been looking forward to this post, as this argument has raged for over 10 years between the many other CAD professionals I know. Ironically, the conclusion I have come to doesn’t have much to do with which way is best. It is more of a philosophical conclusion about social behaviour and perception, explaining why this has remained unresolved for so long. Continue reading “The Modelspace or Paperspace Argument”

CAD Document Management

After a lovely break over Xmas, I thought I’d get back into the swing of things on here.. and I’m starting off the year with CAD document management – a crucial yet sometimes overlooked aspect of computer aided design.

I’ve seen some pretty horrifically non-existent filing systems, so I know all about the woes of poor CAD document management. I’ve had to determine whether a file named “New.dwg” is in fact new as advertised verses a file which has a newer last modified date. I’ve had to perform mass searches on networked drives for “*.dwg”, and sift through hundereds of files looking for something I’ve been handed in a hard copy, that doesn’t have a drawing number on it… Not very helpful at all, and potentially costly to projects as time is wasted trying to find out stuff we should already know. And this is totally avoidable, with very little effort. Hopefully you’re doing this already, but if you’re not, you must implement some standard CAD document management.

What do I mean by this? It can be anything from a full-blown electronic document management system (EDMS) to simply keeping your drawings saved in “/SomePath/CAD/ProjectCode/DrawingNo.dwg”. The scale of the work you are doing usually dictates what level of document management is best suited for the job. More often than not, projects with 50 drawings or less are easily accommodated by a simple folder structure. Above 50 and you might want to consider some managed solution. Look into things like Autodesk Vault to keep better control over your drawings and revisions.

Another option to keep better control over your drawings is to use sheet sets. These are really useful not just for keeping things tidy and well managed, but also has some neat batch plotting functionality that is really worth using.

Whatever you do, have something in place. The most costly option is to have nothing, as this leads to a whole range of problems. Make sure all drawings have a drawing number. Make sure you name your files sensibly. And finally, make sure everyone is singing from the same hymn sheet – ensure you communicate to others working on the same project and get them to work in the same way.

If you want to keep up to date with the posts on my blog, please do subscribe below. I’ve many pearls of wisdom to dish out!

Will

Common causes for AutoCAD® freezing

How many times have you been working in AutoCAD®, and then suddenly it freezes on you? Panic sets in, as you try to remember the last time you saved… You wait… and wait… and… thankfully AutoCAD® un-freezes, this time…

But what actually is the cause of AutoCAD® freezing? It depends – there are many potential reasons for AutoCAD® freezing, but some can be avoided completely with a little understanding of what’s actually happening.

Selections

The first and most obvious reason for AutoCAD® freezing is when we do things to a very large selection. What can sometimes be unexpected is when AutoCAD® freezes when we have merely selected the objects without doing anything to them. This can sometimes leave us gazing at an hourglass thinking “I didn’t ask you to do anything! Why are you freezing on me!?”. Odd as this may seem, there is a reason for it.

When a selection is made, any on screen information that relates to your active selection needs to be updated; otherwise you’ll be working from incorrect information. So, if for example you have the properties window on your screen anywhere, even if it is docked with the auto-hide feature enabled, all the data in the properties window needs to be updated with correct information. The time that this takes is proportional with the amount of things selected, so you can see that simply selecting objects can be the cause of AutoCAD® freezing.

There are ways of working that allow us to drastically reduce the frequency of AutoCAD® freezing when working with a large selection. Make sure you select commands before you make a selection. This sends a clearer instruction to AutoCAD®, and it is dealt with more quickly than if we make the selection first. By selecting first you’re saying to AutoCAD® “Here are some entities that I am interested in – prepare them for me to use in any way”. This is vague, so AutoCAD® has to prepare for anything. However by invoking the command first and making a selection afterwards you’re saying “I only care about performing this action – these are the entities I want to perform it on”. This instruction is much clearer and skips out a lot that we’re not interested in. An extension of this is to get out of the habit of using the Delete key for erasing entities. Yes, it works. But again, picking the erase command first and then the entities sends a clearer message with a very noticeable difference in performance when working with large selections.

Commands

There are a few commands that more commonly cause AutoCAD® to freeze than others. Hatching is one of the main ones, but again, a little know-how can avoid this. A lot of people routinely use the pick-points option for defining a hatch boundary. I personally always try to draw in a way that makes hatching easy. For example, where possible I use closed polylines instead of lines. This allows me to then hatch later by selecting a boundary, eliminating the need to pick points, potentially making AutoCAD® hang. Take a look at my post on the RECTANG command to see what I mean.

When working in 3D, you might be tempted to avoid the 3DORBIT command completely in favour of the SHIFT+MOUSEWHEEL, but there is a reason you should generally use the 3DO command instead. AutoCAD® needs to prepare for 3D orbitting, and if you’re planning on manipulating the drawing a bit, you only want to make AutoCAD® hang for this preparation once. If you use the SHIFT+MOUSEWHEEL method, you’ll make AutoCAD® prepare for 3D orbitting each time you use it, which can be very time consuming on larger drawings. So for very small drawings, its fine to use SHIFT+MOUSEWHEEL, but for everything else use 3DO.

Networked Working

Working on drawings that are saved on some external network has been known to suffer performance issues. Try where possible to work locally, but only where doing so does not undermine whatever document management system you have in place (you do have a structured and coherent document management system.. don’t you??).

Bugs

One particularly prolific bug that I’ve had problems with is the Scale List Bug. Click here to view the solution.

When AutoCAD® Freezes or Hangs…

Wait!!! Do not mash the keys – however tempting that may be! Doing so will only make it take longer. Try to be patient. After a minute or so, you could try a few taps on the Escape key – sometimes you can cancel the command and regain control. After a few mins longer you may want to weigh up whether or not it is worth trying to regain control at all. Is the amount of work you have done since the last save worth rescuing? That will depend on how much work you did. Often, the bulk of the work is the thought processes that went into whatever you did in AutoCAD® – this work has still been done, and you can redo the actual AutoCAD® input quite quickly. If you choose to kill AutoCAD®, you might want to know this useful keyboard shortcut – Ctrl + Shift + Escape, which brings up the task manager.

I will be updating this list in the future so you may want to revisit this post in the future. If you haven’t already, please do subscribe to howtoautocad.com. It is really simple to do – just fill out your email address below, and all you get is an email whenever I post new content. So, it can only be useful to you, and you have nothing to lose 🙂

Will