AutoCAD/LISP routine

Advertisement


Question
Bill,

Another LISP question regarding a routine that I can't get to work. Attached is my most current attempt. I am using AutoCad 2009. I am trying to write a routine that will erase all blocks of a given name (in this case "delta") from a drawing. I then plan to use it on a number of drawings in batch, using a script. Anyway, I can't get the LISP to work. I would have thought there would be lots of example LISPs for this on the internet, but I couldn't find one. Your help is greatly appreciated.

Nathan

(defun c:BEL (/SS Filter n)
 (setq Filter (list '(2  "delta")) )
 (if (setq ss (ssget "_x" Filter))
   (progn
     (setvar "CmdEcho" 0)
     (command ".erase")
     (setq n 0)
     (while (< n (sslength ss))
  (VL-CmdF (ssname ss n))
  (setq n (1+ n))
        )
  (VL-CmdF "")
  )
     (princ "\Invalid selection")
     )
   (princ)
   )

Answer
Nathan
I take a somewhat less complicated approach:

(defun c:nodelta (/ alldeltas)
 (setq alldeltas (ssget "x" (list (cons 2 "delta"))));surprisingly not case sensitive.
 (if alldeltas (command "_.erase" alldeltas ""))
 (if (null alldeltas)(alert "No delta blocks found"))
 (princ)
)

Let me know how it goes.
Bill DeShawn
http://my.sterling.net/~bdeshawn

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.