You are here:

AutoCAD/Manipulating filenames for if then statements

Advertisement


Question
Mr DeShawn, im still in the process of learning lisp routines but been a cad user for a while.  I'm trying to consolidate 2 lisp routines but my initial step is to create an if then logic depending on the drawing's filename.  My questions is, how do i cycle & search for a keyword in my drawing's filename. Typically our drawing filename is '1234-11~F-Detail-MU.dwg' & i want the lisp to do -> if my drawingname contains the word *detail* then do this xxxx if not, do this yyyyy.  Your help is greatly appreciated. Thanks in advance!

Answer
Here is a sub-routine I used to change one character to another:

  (setq sset (ssget))
  (if sset (setq qty (sslength sset)))
  (setq index 0)
  (if qty
     (repeat qty
        (setq ent (ssname sset index))
        (setq elist  (entget ent))
        (setq str (cdr (assoc 1 elist)))
        (setq strlist (assoc 1 elist));                          
        (setq hdr 1);make hdr equal to 1
        (setq newstrlist (cons hdr (strcase str)))
        (setq str (cdr newstrlist))
        (setq OK3 (wcmatch str "*X*"))
(setq OK3 (wcmatch str "*X*"))
        (if OK3
           (progn
              (setq newstr (vl-string-subst "x" "X" str))
              (setq newlist (car (list (cons 1 newstr))))
              (setq oldlist (assoc 1 elist))
              (setq elist (subst newlist oldlist elist))
              (entmod elist)
           ); end progn
        ); end if OK3
      
It changes an upper case "X" to a lower case "x".  It uses a VLISP command, so it requires AutoCAD 2000 or later.
Keep in touch
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.