I hear ya, I hear ya.. What in the hell is a noob doing breaking open lisp scripts? Short answer is a wanton disregard for other peoples property. But more properly I have found in life that you should never stop learning and the best way to learn is to jump in and break shit. This is why God invented the IT department.

AutoCAD is a Ferrari and many users drive it like a Geo. The difference between the two drivers is how much of AutoCAD's horse power they unleash. A small step in turning this ride into a Ferrari is taking advantage of the power of Autolisp. In this example it will be more like putting racing slicks on the Geo and then getting a DUI leaving a brothel, but hey.. we have to start somewhere.

First off you have to have a problem to solve or a routine you need to streamline. In other words if you are gonna break into lisp you should probably have some thing acting a muse to see you through the debugging process. Often the difference between successful scripting and not so successful scripting is some little bullshit syntax. You will need a strong reason driving you through the heartache and loss of time and pulling out your hair over a fucking missing comma.

In this case I am processing a large number of drawings and they have xrefs and not all of them are accounted for. So I cant just bind all as AutoCAD stops at the first missing one. I don't want to unattached all xrefs a I want to keep the little xrefs I do have. Now imagine opening hundreds of drawings and having to select each individual missing xref by hand... sounds very boring and monotonous. This is my muse. This is the work I want to avoid. I'm willing to lose an hour over a broken script to save days of tedious work.

Now its time to act like a professional. Like a modern scholar I jump right into diligently studying the problem... by this I mean run to Google hope to god some one out there has solved the problem for me and has made the solution available online. The gods of the internet are smiling in my favor.

I found a solution here: Gods love me

This script is written or at least provided by Jeff Mishler. I don't know him but its nice to give credit where credit is due.

(defun remove-unloaded-xrefs ()
(vlax-for block (vla-get-blocks
(if (and (= :vlax-true (vla-get-isxref block))
(= 0 (vla-get-count block))
(vla-detach block)
(defun c:rux ()

NOTE: One should be cautious when borrowing lisp scripts if you cant decipher what they actually do. The fuck up potential is great with that. Only use a trusted source's scripts.

Great we have a lisp script... it looks like gibberish... and for many of us that's all it is. For those of us who care not for the health and integrity of our computing systems this looks like adventure.

What happens next is a little down and dirty. We are going off the grid! we are going beyond the bounds of the everyday AutoCAD use. There are a couple ways to do this. My favorite is to use good ole windows note pad to script. I then just click and drag the file into AutoCAD but that's because of old habits from other types of programs, so ill try to show you the proper way to handle these things.

You can navigate to the Manage tab>Applications panel and click on Visual lisp or you can type in VLISP into the command bar.

This brings up the Visual Lisp scripting environment. Now I know this environment looks important and breakable and scary... and it is... but you can tinker just a little without hurting your self too much. Just take a deep breath and take solace in the fact that its THEIR fault for giving you, the office idiot, a tool that you can hurt things with.

What we do next is pretty simple. Just copy the script from above and past it into the blank untitled document. Next click on file and save as. Give it a name and viola, we have a lisp script!

Now that we have created a lisp we have to load it in order to use it. Having a screwdriver in your tool box doesn't help if you don't take the toolbox to the work site. This process is fairly simple as well. Click on load application right next to where we launched the Visual lisp editor. It is located on the Manage Tab>Applications Panel. Or you can type APPLOAD into the command bar.

Navigate to your file and click load. Once you have loaded it all that is left is to close the dialog. This brings your new lisp into your CAD session. It should be noted that for each new session you will have to do this step. So in other words if you close AutoCAD and open it again, your lisp will need to be reloaded if you want to use it again. There is a simple way to put it in the start up, but I might cover that another time. Ill give you a hint though, its in the same dialog box.

All that is left is to run it and watch the magic happen.... so now... uhh... how the fuck do you run it? If you look back at the script code we put in, it also shows you the command to type into the command bar to run your script. Specifically the part that looks like this (defun c:rux (). This tell us that the function which is called from the command line is RUX. Its a handy little tip to know that the "c:" usually indicates what the main function call is for the scripts.

So that's it! Just type RUX and away it goes...

This is how the story would go if I weren't a cursed ginger. For my purposes I actually had to change the code a little bit. I needed the "0" parameter set to "1" in the code. This changed it from detaching unloaded files to detaching not found files. But that's it. Scripts are a lot of fun and can be extremely powerful when they work. I hope this helps my fellow noobicans take a look into the possibility of unleashing their Ferrari... or at least consider test driving a mustang.