home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 November / Dppcpro1198.iso / Nov / Intelcad / Uncompressed / API / LISP / SAMPLE.LSP < prev   
Encoding:
Lisp/Scheme  |  1998-02-19  |  10.2 KB  |  250 lines

  1. ; Sample.lsp
  2. ; Release 1.0   
  3. ; Rick Gardner
  4. ;
  5. ; .............................................................................
  6. ;
  7. ; Copyright (c) 1998 by Visio Corporation.  All rights reserved.
  8. ;
  9. ; The Software is subject to the license agreement that accompanies 
  10. ; or is included with the Software, which specifies the permitted 
  11. ; and prohibited uses of the Software. Any unauthorized duplication 
  12. ; or use of Visio Corporation Software, in whole or in part, in print, 
  13. ; or in any other storage and retrieval system is prohibited.
  14. ; To the maximum extent permitted by applicable law, Visio Corporation
  15. ; and its suppliers disclaim any and all warranties and conditions,
  16. ; either express or implied, including, without limitation, implied
  17. ; warranties of merchantability, fitness for a particular purpose,
  18. ; title, and non-infringement, and those arising out of usage of trade
  19. ; or course of dealing, concerning these materials.  These materials
  20. ; are provided "as is" without warranty of any kind.
  21. ; .............................................................................
  22.  
  23.  
  24. ;*********************************************************************
  25. ;   CAD DXF TRANSLATOR/WRITER FOR STEPPING THROUGH DRAWING ENTITIES
  26. ;*********************************************************************
  27. (defun c:dxfread ( / picklist ans ent vname ss ckent filnam )
  28.     (setq ans "S")
  29.     (while (and (/= ans "") (/= ans "Q"))
  30.         (if (= ans "V")
  31.             (if (setq vname (eval (read (getstring "\nEnter variable name to use: "))))
  32.                   (progn
  33.                       (if (= (type vname) 'ENAME)
  34.                           (setq ent vname)
  35.                       )
  36.                       (if (= (type vname) 'LIST)
  37.                           (setq ent (cdr (assoc -1 vname)))
  38.                       )
  39.                       (setq picklist (cons ent picklist))
  40.                   )
  41.                   (princ "\n**********Variable name not valid**************")
  42.             )
  43.         )
  44.         (if (= ans "D") (progn
  45.              (setq ss (ssget "X")
  46.                    ckent (ssname ss (- (sslength ss) 1))
  47.              )
  48.              (if (eq ckent ent)
  49.                   (princ "\n********First entity in DWG encountered********")
  50.                   (while ckent
  51.                        (if (eq (entnext ckent) ent)
  52.                             (setq ent ckent
  53.                                   picklist (cons ent picklist)
  54.                                   ckent nil
  55.                             )
  56.                             (setq ckent (entnext ckent))
  57.                        )
  58.                   )
  59.              )
  60.         ))
  61.         (if (= ans "W") (progn
  62.              (setq filnam (getstring "\nEnter name of file to write: "))
  63.              (setq fil (open filnam "w"))
  64.              (princ (strcat "\nCommand is EM to read modified entity data from " filnam " and perform entmake."))
  65.         ))
  66.         (if (= ans "P") (if (setq picklist (cdr picklist))
  67.                                             (setq ent (car picklist))
  68.                                             (princ "\n********Beginning of picklist encountered********")
  69.                                   )
  70.         )
  71.         (if (= ans "N") (if (entnext ent) (progn
  72.                                         (setq ent (entnext ent))
  73.                                         (setq picklist (cons ent picklist))
  74.                                         ) ;progn
  75.                                         (princ "\n********Last entity in DWG encountered********")
  76.                                   )
  77.         )
  78.         (if (= ans "L") (progn
  79.                             (setq ent (entlast))
  80.                             (while (entnext ent) (setq ent (entnext ent)))
  81.                             (setq picklist (cons ent picklist))
  82.         ))
  83.         (if (= ans "S") (progn
  84.                                   (setq ent (car (entsel)))
  85.                                   (if picklist
  86.                                         (setq picklist (cons ent picklist))
  87.                                         (setq picklist (list ent))
  88.                                   ); if
  89.                                   );progn
  90.         )
  91.         (setq elist (entget ent (list "*")))
  92.         (if (not (member (cdr (assoc 0 elist)) '("VERTEX" "ATTRIB" "SEQEND")))
  93.             (redraw ent 3)
  94.         )
  95.         (setq count 1)
  96.         (while (car elist)
  97.             (if (= (caar elist) -3) (progn
  98.                 (setq elist (cdar elist))
  99.                 (while (setq xlist (car elist))
  100.                     (while (car xlist)
  101.                          (if (= ans "W")(progn
  102.                               (prin1 (car xlist) fil)
  103.                               (write-char 10 fil)
  104.                               )(progn
  105.                               (print (car xlist))
  106.                          ))
  107.                          (setq xlist (cdr xlist))
  108.                          (setq count (+ 1 count))
  109.                          ;(if (and (/= ans "W") (> count 23)) (progn
  110.                          ;    (TEXTSCR)
  111.                          ;    (getstring "\nHit enter to continue")
  112.                          ;    (setq count 1)
  113.                          ;))
  114.                     )
  115.                     (setq elist (cdr elist))
  116.                 )
  117.                 (if (car elist)
  118.                     (if (= ans "W") (progn
  119.                          (prin1 (car elist) fil)
  120.                          (write-char 10 fil)
  121.                          )(progn
  122.                          (print (car elist))
  123.                     ))
  124.                 )
  125.             )(progn
  126.                 (if (= ans "W") (progn
  127.                     (prin1 (car elist) fil)
  128.                     (write-char 10 fil)
  129.                     )(progn
  130.                     (print (car elist))
  131.                 ))
  132.             ));progn,if
  133.             (princ)
  134.             (setq count (+ 1 count))
  135.             ;(if (and (/= ans "W") (> count 23)) (progn
  136.             ;    (TEXTSCR)
  137.             ;    (getstring "\nHit enter to continue")
  138.             ;    (setq count 1)
  139.             ;))
  140.             (setq elist (cdr elist))
  141.         )
  142.         (TEXTSCR)
  143.         (if (= ans "W") (close fil))
  144.         (setq ans (strcase (getstring "\nWrite, Next, Select, prev Pick, prev Dwg, Last dwg, Var or Quit? <Q> ")))
  145.     );while
  146.     (GRAPHSCR)
  147.     (redraw)
  148. ) ;defun
  149. (princ "\nDXFREAD loaded")
  150. ;*********************************************************************
  151. ;COMPANION TO PREVIOUS FUNCTION FOR MAKING ENT FROM A FILE
  152. ;*********************************************************************
  153. (defun c:dxfemake ( / )
  154.     (setq filnam (findfile (getstring "\nEnter name of file to read for entmake: ")))
  155.     (if (not filnam) (progn
  156.         (alert (strcat "File " filnam " not found."))
  157.         (quit)
  158.     ))
  159.     (setq elist nil xlist nil)
  160.     (setq fil (open filnam "r"))
  161.     (while (setq ln (read-line fil))
  162.         (if (not (wcmatch ln "*<Entity name:*"))(progn
  163.             (setq ln (read ln))
  164.             (if (and (not xlist) (= (type ln) 'LIST)) ;std cad data
  165.                (if elist (setq elist (cons ln elist))
  166.                    (setq elist (list ln))
  167.                 )
  168.             )
  169.             (if (and xlist (= (type ln) 'STR))(progn  ;not 1st xdata appname
  170.               (setq xlist (reverse xlist))
  171.               (setq xlist (cons (list ln) xlist))
  172.               (setq xlist (reverse xlist))
  173.               (regapp ln)
  174.             ))
  175.             (if (and (not xlist) (= (type ln) 'STR))(progn;1st xdata appname
  176.                (setq xlist (list -3 (list ln)))
  177.                (regapp ln)
  178.             ))
  179.             (if (and xlist (= (type ln) 'LIST))(progn  ;xdata info
  180.                (setq xlist (reverse xlist))
  181.                (setq xlist (cons (reverse (cons ln (reverse (car xlist)))) (cdr xlist)))
  182.                (setq xlist (reverse xlist))
  183.             ))
  184.         ));progn,if
  185.     );while
  186.     (close fil)
  187.     (if xlist (setq elist (cons xlist elist)))
  188.     (setq elist (reverse elist))
  189.     (if (entmake elist)
  190.         (princ (strcat "\nEntmake successful from file " filnam "."))
  191.     (progn
  192.         (princ (strcat "\nEntmake failed from file " filnam ".  ERRNO is: "))
  193.     (princ (getvar "ERRNO"))
  194.     ))
  195.     (princ)
  196. );defun
  197. (princ "\tDXFEMAKE loaded")
  198. ;*********************************************************************
  199. ;FUNCTION TO UPDATE ALL BLOCK DEFINITIONS IN DRAWING
  200. ;*********************************************************************
  201. (defun c:redoblks ( / blist belist rauto)
  202.         (if (setq blist (cdr (assoc 2 (tblnext "BLOCK" T)))) (progn
  203.                 (setq blist (list blist))
  204.                 (while (setq belist (tblnext "BLOCK"))
  205.                         (setq blist (cons (cdr (assoc 2 belist)) blist))
  206.                 )
  207.                 (setq rauto (getvar "regenmode"))
  208.                 (setvar "regenmode" 0)
  209.                 (foreach blk blist
  210.                         (if (findfile (strcat blk ".DWG")) (progn
  211.                             (setq blk (strcat blk "="))
  212.                             (command "insert" blk)
  213.                             (command)
  214.                         ))
  215.                 )
  216.                 (setvar "regenmode" rauto)
  217.                 (COMMAND "REGEN")
  218.                 (PRINC "\nAll block definitions updated.")
  219.         ))
  220.         (princ)
  221. );DEFUN
  222. (princ "\nREDOBLKS loaded")
  223.  
  224. ;*********************************************************************
  225. ;COMMAND TO ECHO BACK BLOCK AND FILE DATA
  226. ;*********************************************************************
  227. (defun c:find ( / filenam gotit count)
  228.     (setq filenam (getstring "\nEnter name and extension (if not .DWG) to locate: "))
  229.     (setq count 1 gotit nil)
  230.     (while (< count (strlen filenam))
  231.         (setq x (substr filenam count 1))
  232.         (if (= x ".") (setq gotit 1))
  233.         (setq count (+ 1 count))
  234.     )
  235.     (if (not gotit) (setq filenam (strcat filenam ".DWG")))
  236.     (if (findfile filenam) (progn
  237.         (princ (strcat "\nFile found file as " (findfile filenam)))
  238.         (if (tblsearch "block" (substr filenam 1 (- (strlen filenam) 4)))
  239.             (princ " and as block in current drawing")
  240.         )
  241.         (princ ".")
  242.         ) ;progn
  243.         (princ (strcat "\nFile " filenam " not found."))
  244.     )
  245. (princ)
  246. );defun
  247. (princ "\tFIND loaded")
  248. (princ)
  249.