The error message would mean to me that someone has the drawing open. But you shouldn't get the error, since that part of the code is wrapped up in a ' vl-catch-all-apply ' call.
The second part is most likely because it isn't closing the drawing, and releasing the ObjectDBX object. Which shouldn't happen either, unless it is error'ing with the portion of the code about the images.
To fix both of these problems, you could create a local error function, just for this function. Within that section, you will see if the ODBX object equals anything, and if so, release it and set it to nil. I know if you have it in the local vars list this will happen, but I got in the habit of just setting it anyway.
Hope that is enough to get you going with trying to code it yourself. If you get stuck, let us know, and we can help you some more.