Tutorial: Page (1) of 3 - 11/01/01 Email this story to a friend. email article Print this page (Article printing at MyDmn.com).print page facebook

Making an AutoLISP File

Part 2 of a 2-Part Series By Jos van Doorn

Last week, we were working on a program for making an AutoLISP file that can make a drawing. As promised here is the complete listing of the program.




(defun c:emlst ()
   (setvar "cmdecho" 0)
   (setq ct T)
   (while ct
      (setq ct nil)
      (setq et (entnext))
      (while et
         (setq el (entget et)
               tp (cdr (assoc 0 el))
         )
         (if (or (= tp "LWPOLYLINE")
                 (= tp "INSERT")
                 (= tp "MTEXT")
                 (= tp "DIMENSION")
             )
            (setq ct T)
         )
         (setq et (entnext et))
      )
      (if ct
         (command "explode" "all" "")
      )
   )
   (setq nm (getstring T "Name of file (no extension):
   ")
         fn (strcat "c:/"
                    nm
                    ".lsp"
            )
   )
   (setq fl (open fn "w"))
   (write-line (strcat "(defun c:" nm " ()") fl)
   (setq et (entnext))
   (while et
      (setq el (entget et)
            tp (cdr (assoc 0 el))
      )
      (write-line "(entmake '(" fl)
      (print (assoc 0 el) fl)
      (cond
         ((= tp "LINE")
            (print (assoc 10 el) fl)
            (print (assoc 11 el) fl)
         )
         ((= tp "CIRCLE")
            (print (assoc 10 el) fl)
            (print (assoc 40 el) fl)
         )
         ((= tp "ARC")
            (print (assoc 10 el) fl)
            (print (assoc 40 el) fl)
            (print (assoc 50 el) fl)
            (print (assoc 51 el) fl)
         )
         ((= tp "TEXT")
            (print (assoc 10 el) fl)
            (print (assoc 40 el) fl)
            (print (assoc 1 el) fl)
            (print (assoc 50 el) fl)
         )
         ((= tp "SOLID")
            (print (assoc 10 el) fl)
            (print (assoc 11 el) fl)
            (print (assoc 12 el) fl)
            (print (assoc 13 el) fl)
         )
      )
      (princ "))" fl)
      (princ " " fl)
      (setq et (entnext et))
   )
   (princ ")" fl)
   (close fl)
   (setvar "cmdecho" 1)
   (princ)
)



Page: 1 2 3 Next Page


Related Keywords:AutoLISP, Jos Van Doorn

HOT THREADS on DMN Forums
Content-type: text/html  Rss  Add to Google Reader or
Homepage    Add to My AOL  Add to Excite MIX  Subscribe in
NewsGator Online 
Real-Time - what users are saying - Right Now!

Our Privacy Policy --- @ Copyright, 2015 Digital Media Online, All Rights Reserved