home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / MFACE.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1990-08-01  |  6.1 KB  |  214 lines

  1. ;;;   MFACE.LSP  
  2. ;;;   Copyright (C) 1990 by Autodesk, Inc.  
  3. ;;;    
  4. ;;;   Permission to use, copy, modify, and distribute this software and its
  5. ;;;   documentation for any purpose and without fee is hereby granted.  
  6. ;;;
  7. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  8. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  9. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  10. ;;;   
  11. ;;;--------------------------------------------------------------------------
  12. ;;; DESCRIPTION
  13. ;;;   C:MFACE -- Pmesh creator.
  14. ;;;   
  15. ;;;   This routine is a front end to the PFACE 
  16. ;;;   command in AutoCAD.  It allows the user to easily
  17. ;;;   create pface meshes at the command prompt.
  18.  
  19. ;;;   Training Department / J.F.
  20. ;;;   5/04/90
  21. ;;;
  22. ;;;----- Redefined error function ----------------------------
  23.  
  24. (defun newerr (s)
  25.   (if (/= s "Function cancelled")
  26.       (princ (strcat "\nError: " s))
  27.   )
  28.   (setq *error* olderr)
  29.   (setvar "CMDECHO" cmdecho)
  30.   (redraw)
  31.   (princ)
  32. )
  33.  
  34. ;;;
  35. ;;;----- Draw PFACE ----------------------------------------
  36. ;;;
  37. (defun drawrat ()
  38.   (command "PFACE")
  39.   (while (car vlist)
  40.     (command (car vlist))
  41.     (setq vlist (cdr vlist))
  42.   )
  43.   (command "")
  44.   (while (setq facelist (car masterfl))
  45.     (command "color" (car colorlst))
  46.     (command "layer" (car layerlst))
  47.     (while (car facelist)
  48.            (command (car facelist))
  49.            (setq facelist (cdr facelist))
  50.     )
  51.     (command "")
  52.     (setq layerlst (cdr layerlst))
  53.     (setq colorlst (cdr colorlst))
  54.     (setq masterfl (cdr masterfl))
  55.   )
  56.   (command "")
  57. )
  58.  
  59. ;;;
  60. ;;;----- Find current entity color ---------------------------
  61. ;;; The system variable "CECOLOR" gives the color number and
  62. ;;; the color name (i.e. "1 red") for the first 7 colors.  
  63. ;;; This function strips the color name and returns the color
  64. ;;; number.
  65. ;;;
  66. (defun getcolor (/ max ctr cecolor)
  67.   (setq colnam nil)
  68.   (setq cecolor (getvar "CECOLOR"))
  69.   (setq ctr 1)
  70.   (setq max (strlen cecolor))
  71.   (while (< ctr max)
  72.     (if (= (substr cecolor ctr 1) " ")
  73.       (progn
  74.         (setq colnam (substr cecolor 1 (- ctr 1)))
  75.         (setq ctr max)
  76.       )
  77.       (setq ctr (1+ ctr))
  78.     )
  79.   )
  80.   (if (not colnam) (setq colnam cecolor))
  81. )
  82.  
  83. ;;;
  84. ;;;----- Prompt for layer, chk table, add to layer list ------
  85. ;;;
  86. (defun setlay (/ oldlnam)
  87.   (setq oldlnam laynam)
  88.   (setq laynam 
  89.       (getstring (strcat "\nLayer name <" oldlnam ">: "))
  90.   )
  91.   (if (= laynam "")                   ;if accepting default layer name
  92.     (setq laynam oldlnam)             ;then set to default
  93.     (progn                            ;else check layer table
  94.       (while (not (tblsearch "LAYER" laynam))
  95.         (prompt (strcat "\nCannot find layer " laynam))
  96.         (setq laynam 
  97.           (getstring (strcat "\nLayer name <" oldlnam ">: "))
  98.         )
  99.         (if (= laynam "") (setq laynam oldlnam))
  100.       )
  101.     )
  102.   )
  103. )
  104. ;;;
  105. ;;;----- Prompt for color, convert # to string ---------------
  106. ;;;
  107. (defun setcol (/ oldcolor)
  108.   (setq oldcolor colnam)
  109.   (initget "Red Blue Green Cyan Byblock Yellow Magenta White Bylayer")
  110.   (setq colnam 
  111.     (getint (strcat "\nColor no. <" colnam ">: "))
  112.   )
  113.   (cond 
  114.     ((numberp colnam) (setq colnam (itoa colnam)))
  115.     ((equal colnam nil) (setq colnam oldcolor))
  116.   )
  117. )
  118.  
  119. ;;;
  120. ;;; ----- Set grdraw color -----------------------------------
  121. ;;; This function set the color number for the grdraw function
  122. ;;; if GRCOLOR does not contain the color number (i.e. if 
  123. ;;; set to "red" it would change it to "1").
  124. ;;;
  125. (defun subcolor ()
  126.   (cond 
  127.     ((equal grcolor "Red")     (setq grcolor 1))
  128.     ((equal grcolor "Yellow")  (setq grcolor 2))
  129.     ((equal grcolor "Green")   (setq grcolor 3))
  130.     ((equal grcolor "Cyan")    (setq grcolor 4))
  131.     ((equal grcolor "Blue")    (setq grcolor 5))
  132.     ((equal grcolor "Magenta") (setq grcolor 6))
  133.     ((equal (strcase grcolor) "BYLAYER") ;find layer color
  134.       (setq laylist (tblsearch "layer" (last layerlst)))
  135.       (setq grcolor (cdr (assoc 62 laylist)))
  136.     )
  137.     ((equal (strcase grcolor) "BYBLOCK") (setq grcolor 7))
  138.     ( T (setq grcolor (atoi grcolor)))
  139.   )
  140. )
  141.  
  142. ;;;
  143. ;;;----- Add vertex to face list, find order in list ---------
  144. ;;; This function adds the vertex point to the vertex list if
  145. ;;; it is not in the vertex list.  Then it finds the order of
  146. ;;; the vertex in the list and add it to the face list.
  147. ;;;
  148. (defun addpt (/ remain remain-l vlist-l v-order)
  149.   (if (not (setq remain (member pt vlist)))
  150.     (progn
  151.       (setq vlist (append vlist (list pt)))
  152.       (setq remain (member pt vlist))
  153.     )
  154.   )
  155.   (setq remain-l (length remain))
  156.   (setq vlist-l (length vlist))
  157.   (setq v-order (1+ (- vlist-l remain-l)))
  158.   (setq facelist (append facelist (list v-order)))
  159. )
  160.  
  161. ;;;
  162. ;;;----- Get vertex, add face list to master face list -------
  163. ;;;
  164. (defun getvts (/ grcolor 1st prev-pt)
  165.   (setq layerlst (append layerlst (list laynam)))
  166.   (setq colorlst (append colorlst (list colnam)))
  167.   (setq grcolor colnam ctr 1)
  168.   (if (not (numberp grcolor)) (subcolor))
  169.   (setq prev-pt pt) (setq 1st pt)
  170.   (while (setq pt (getpoint pt "\nSelect Vertex: "))
  171.     (grdraw prev-pt pt grcolor 0)
  172.     (if (> ctr 2)
  173.       (grdraw 1st pt grcolor 1)
  174.     )
  175.     (setq prev-pt pt)
  176.     (addpt)
  177.     (setq ctr (1+ ctr))
  178.   )
  179.   (grdraw prev-pt 1st grcolor 0)
  180.   (setq masterfl (append masterfl (list facelist)))
  181.   (setq facelist nil)
  182. )
  183.  
  184. ;;;
  185. ;;;----- Primary function ------------------------------------
  186. ;;;
  187. (defun C:MFACE (/ facelist masterfl vlist colorlst layerlst
  188.                    laynam pt)
  189.   (setq olderr  *error*
  190.         *error* newerr
  191.         again   T
  192.         cmdecho (getvar "CMDECHO")
  193.         laynam  (getvar "CLAYER")
  194.   )
  195.   (setvar "CMDECHO" 0)
  196.   (getcolor)
  197.   (while again
  198.     (initget "Color Layer")
  199.     (setq pt (getpoint "\nLayer/Color/<Select vertex>: "))
  200.     (cond 
  201.       ((equal pt "Color") (setcol))
  202.       ((equal pt "Layer") (setlay))
  203.       ((not pt) (setq again nil))
  204.       (T (addpt) (getvts))
  205.     )
  206.   )
  207.   (if masterfl (drawrat))
  208.   (redraw)
  209.   (setvar "CMDECHO" cmdecho)
  210.   (setq *error* olderr)
  211.   (princ)
  212. )
  213.  
  214.