Author Topic: Remove Unreferenced & UNLOADED xRefs, PDFs, DWFs, DGNs and Images  (Read 1617 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
I have checked for routines that will remove underlays of all sorts that are unreferenced (not actually inserted into the drawing) or that are unloaded (inserted, but have been unloaded for various reasons). I had found routines that claimed they would do this, just to have them remove all PDFs for example, not just unreferenced/unloaded ones or some would just remove unreferenced, but leave unloaded. In all fairness, many of these routines were from 2013 or earlier, so the way AutoCAD works may have changed since then.

So I have taken to writing my own, which is indeed functional. I would post it in the Show Your Code section; however, there is a bug in it that I cannot figure out. It works the first time just fine, but in many cases if you try to run it a second time on the same drawing, it will return the following error:

Automation Error. Object was erased

I believe that aside from this error, it should work on any version of AutoCAD that can handle PDFs.

Due to the size of the code, it is uploaded as an attachment here.

I tried to give credit where credit is due; however, some of the code was so old that even the person posting didn't know where it came from. So, if you see any code that is yours and it is not credited, please speak up.

ETA:
Additional bugs have been removed

One key detail to note is that changes are not reflected in the XREF palette until you save and close the drawing and reopen it. The changes should be reflected in the classicxref dialog box right away, but sometimes they aren't. When in doubt, save the drawing, close it and reopen it.
« Last Edit: May 04, 2022, 07:11:40 PM by cmwade77 »

stevej

  • Newt
  • Posts: 30
Re: Remove Unreferenced & UNLOADED xRefs, PDFs, DWFs, DGNs and Images
« Reply #1 on: May 11, 2021, 08:25:10 PM »
Using Autocad 2014.
For first run, dropped your lsp file on open drawing, then issued FixReferences command. Ran just fine.
Pressed enter key to repeat last command, and no errors reported, but drawing was empty of unreferenced items at that point.
Pressed space bar and Enter key numerous times to repeat last command with no errors.
Same story on all drawings I tried it on.

Then tried with Autocad 2020. No errors reported there, either.

Did not try with PDF underlays. Not familiar with those things.

Steve

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Remove Unreferenced & UNLOADED xRefs, PDFs, DWFs, DGNs and Images
« Reply #2 on: May 12, 2021, 11:53:16 AM »
I suppose the error could also be on specific drawings or situations, more testing is needed to find out. But I am glad it is working for someone else, this is a major item I need to be able to properly bind all xRefs in drawings as well as overcome some other issues.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Remove Unreferenced & UNLOADED xRefs, PDFs, DWFs, DGNs and Images
« Reply #3 on: May 12, 2021, 01:56:07 PM »
It looks like there is still some more work to do. Not all PDFs get removed properly and I want to add in removing files when they aren't found.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Remove Unreferenced & UNLOADED xRefs, PDFs, DWFs, DGNs and Images
« Reply #4 on: May 04, 2022, 12:14:42 PM »
I have removed additional bugs, posting an updated version.