autocadcaddwg

How can I automate deleting of certain items in a DWG file?


When I export DWG files from Archicad I often get wipeouts that I want to delete. I do this in Autocad LT (we unfortunately don't have regular Autocad) with QSEL and selecting all wipeouts and pressing delete. This requires me to open every DWG file and doing it manually, and for every new export I have to redo it, which quickly becomes tedious.

Is there any way to automate this process, either in Autocad or in another (free/cheap) software?


Solution

  • I would suggest following the general procedure that I outline in my answer here, whereby you would develop an AutoLISP program (.lsp) to operate autonomously (i.e. with no user prompts) on the active drawing, and then use a basic AutoCAD Script (.scr) to successively open each drawing in a set, load & run the program, and then save & close the drawing.

    An AutoLISP program to automatically delete all wipeouts (in all layouts) in the active drawing can be as simple as the following:

    (defun c:delwipe ( / idx sel )
        (if (setq sel (ssget "_X" '((0 . "WIPEOUT"))))
            (repeat (setq idx (sslength sel))
                (entdel (ssname sel (setq idx (1- idx))))
            )
        )
        (princ)
    )
    

    If you were to copy the above code to a .lsp file (which may be created in Windows Notepad or other plain text editor) and save it in an AutoCAD Support File Search Path (call the file delwipe.lsp, say), you could then create an AutoCAD Script (.scr) to run the program across multiple drawings.

    Consider the following simple script:

    _.open "C:/Your Folder/Drawing1.dwg" (load "delwipe.lsp" nil) (if c:delwipe (c:delwipe)) _.qsave _.close
    _.open "C:/Your Folder/Drawing2.dwg" (load "delwipe.lsp" nil) (if c:delwipe (c:delwipe)) _.qsave _.close
    _.open "C:/Your Folder/Drawing3.dwg" (load "delwipe.lsp" nil) (if c:delwipe (c:delwipe)) _.qsave _.close
    

    Such a script could even be generated using a batch file to send the drawing filenames to the script file.

    Assuming you've copied the above script lines to a plain text file (named delwipe.scr, say) and adjusted the drawing filenames appropriately, you can then run the script from a new drawing in AutoCAD using the SCRIPT command.