home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SUPPORT / 3DARRAY.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1995-02-08  |  8.7 KB  |  299 lines

  1. ; Next available MSG number is    29
  2. ; MODULE_ID LSP_3DARRAY_LSP_
  3. ;;;
  4. ;;;    3darray.lsp
  5. ;;;
  6. ;;;    Copyright (C) 1987, 1988, 1990, 1992, 1994 by Autodesk, Inc.
  7. ;;;
  8. ;;;    Permission to use, copy, modify, and distribute this software
  9. ;;;    for any purpose and without fee is hereby granted, provided
  10. ;;;    that the above copyright notice appears in all copies and
  11. ;;;    that both that copyright notice and the limited warranty and
  12. ;;;    restricted rights notice below appear in all supporting
  13. ;;;    documentation.
  14. ;;;
  15. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  16. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  17. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  18. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  19. ;;;    UNINTERRUPTED OR ERROR FREE.
  20. ;;;
  21. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  22. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  23. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  24. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  25. ;;;
  26. ;;;.
  27. ;;;  Functions included:
  28. ;;;       1) Rectangular ARRAYS (rows, columns & levels)
  29. ;;;       2) Circular ARRAYS around any axis
  30. ;;; 
  31. ;;;  All are loaded by: (load "3darray")
  32. ;;; 
  33. ;;;  And run by:
  34. ;;;       Command: 3darray
  35. ;;;                Select objects:
  36. ;;;                Rectangular or Polar array (R/P): (select type of array)
  37. ;;;
  38. ;;; ===================== load-time error checking ============================
  39. ;;;
  40.  
  41.   (defun ai_abort (app msg)
  42.      (defun *error* (s)
  43.         (if old_error (setq *error* old_error))
  44.         (princ)
  45.      )
  46.      (if msg
  47.        (alert (strcat " Error en la aplicaci≤n: "
  48.                       app
  49.                       " \n\n  "
  50.                       msg
  51.                       "  \n"
  52.               )
  53.        )
  54.      )
  55.      (exit)
  56.   )
  57.  
  58. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  59. ;;; and then try to load it.
  60. ;;;
  61. ;;; If it can't be found or it can't be loaded, then abort the
  62. ;;; loading of this file immediately, preserving the (autoload)
  63. ;;; stub function.
  64.  
  65.   (cond
  66.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  67.  
  68.      (  (not (findfile ;|MSG0|;"ai_utils.lsp"))                     ; find it
  69.         (ai_abort "3DARRAY"
  70.                   (strcat "No se puede localizar el archivo AI_UTILS.LSP."
  71.                           "\n Compruebe el directorio de soporte.")))
  72.  
  73.      (  (eq ;|MSG0|;"failed" (load "ai_utils" ;|MSG0|;"failed"))            ; load it
  74.         (ai_abort "3DARRAY" "No se puede cargar el archivo AI_UTILS.LSP"))
  75.   )
  76.  
  77.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  78.       (ai_abort "3DARRAY" nil)         ; a Nil <msg> supresses
  79.   )                                    ; ai_abort's alert box dialog.
  80.  
  81. ;;; ==================== end load-time operations ===========================
  82. ;;; 
  83. ;;;******************************** MODES ********************************
  84. ;;; 
  85. ;;; System variable save
  86.  
  87. (defun MODES (a)
  88.   (setq MLST '())
  89.   (repeat (length a)
  90.     (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
  91.     (setq a (cdr a))
  92.   )
  93. )
  94.  
  95. ;;;******************************** MODER ********************************
  96. ;;; 
  97. ;;; System variable restore
  98.  
  99. (defun MODER ()
  100.   (repeat (length MLST)
  101.     (setvar (caar MLST) (cadar MLST))
  102.     (setq MLST (cdr MLST))
  103.   )
  104. )
  105.  
  106. ;;;******************************** 3DAERR *******************************
  107. ;;; 
  108. ;;; Standard error function
  109.  
  110. (defun 3DAERR (st)                    ; If an error (such as CTRL-C) occurs
  111.                                       ; while this command is active...
  112.   (if (/= st "Funci≤n cancelada")
  113.       (princ (strcat "\nError: " s))
  114.   )
  115.   (command "_.UNDO" "_E")
  116.   (ai_undo_off)
  117.   (moder)                             ; Restore system variables
  118.   (setq *error* olderr)               ; Restore old *error* handler
  119.   (princ)
  120. )
  121.  
  122. ;;;******************************* P-ARRAY *******************************
  123. ;;; 
  124. ;;; Perform polar (circular) array around any axis
  125.  
  126. (defun P-ARRAY (/ n af yn cen c ra)
  127.  
  128.   ;; Define number of items in array
  129.   (setq n 0)
  130.   (while (<= n 1)
  131.     (initget (+ 1 2 4))
  132.     (setq n (getint "\nN·mero de elementos: "))
  133.     (if (= n 1)
  134.       (prompt "\nEl n·mero de elementos debe ser mayor que 1")
  135.     )
  136.   )
  137.  
  138.   ;; Define angle to fill
  139.   (initget 2)
  140.   (setq af (getreal "\nAngulo a rellenar <360>: "))
  141.   (if (= af nil) (setq af 360))
  142.  
  143.   ;; Are objects to be rotated?
  144.   (initget "Sφ No")
  145.   (setq yn (getkword "\n┐Girar objetos al copiarlos? <S>: "))
  146.   (if (null yn)
  147.     (setq yn "Sφ")
  148.   )
  149.   (setq yn (if (= yn "Sφ") "_Y" "_N"))
  150.  
  151.   ;; Define center point of array
  152.   (initget 17)
  153.   (setq cen (getpoint "\nCentro de la matriz: "))
  154.   (setq c (trans cen 1 0))
  155.  
  156.   ;; Define rotational axis
  157.   (initget 17)
  158.   (setq ra (getpoint cen "\nSegundo punto del eje de rotaci≤n: "))
  159.   (while (equal ra cen)
  160.     (princ "\nPunto no vßlido. El segundo punto no puede ser igual al centro.")
  161.     (initget 17)
  162.     (setq ra (getpoint cen "\nPor favor, intente de nuevo: "))
  163.   )
  164.   (setvar "UCSFOLLOW" 0)
  165.   (setvar "GRIDMODE" 0)
  166.   (command "_.UCS" "_ZAXIS" cen ra)
  167.   (setq cen (trans c 0 1))
  168.  
  169.   ;; Draw polar array
  170.   (command "_.ARRAY" ss "" "_P" cen n af yn)
  171.   (command "_.UCS" "_p")
  172. )
  173.  
  174. ;;;******************************* R-ARRAY *******************************
  175. ;;; 
  176. ;;; Perform rectangular array
  177.  
  178. (defun R-ARRAY (/ nr nc nl flag x y z c el en ss2 e)
  179.  
  180.   ;; Set array parameters
  181.   (while (or (= nr nc nl nil) (= nr nc nl 1))
  182.     (setq nr 1)
  183.     (initget (+ 2 4))
  184.     (setq nr (getint "\nN·mero de filas (---) <1>: "))
  185.     (if (null nr) (setq nr 1))
  186.     (initget (+ 2 4))
  187.     (setq nc (getint "\nN·mero de columnas (|||) <1>: "))
  188.     (if (null nc) (setq nc 1))
  189.     (initget (+ 2 4))
  190.     (setq nl (getint "\nN·mero de niveles (...) <1>: "))
  191.     (if (null nl) (setq nl 1))
  192.     (if (= nr nc nl 1)
  193.       (princ "\nMatriz de un solo elemento; nada por hacer.\nPor favor, intente de nuevo")
  194.     )
  195.   )
  196.   (setvar "ORTHOMODE" 1)
  197.   (setvar "HIGHLIGHT" 0)
  198.   (setq flag 0)                       ; Command style flag
  199.   (if (/= nr 1)
  200.     (progn
  201.     (initget (+ 1 2))
  202.     (setq y (getdist "\nDistancia entre filas (---): "))
  203.     (setq flag 1)
  204.     )
  205.   )
  206.   (if (/= nc 1)
  207.     (progn
  208.     (initget (+ 1 2))
  209.     (setq x (getdist "\nDistancia entre columnas (|||): "))
  210.     (setq flag (+ flag 2))
  211.     )
  212.   )
  213.   (if (/= nl 1)
  214.     (progn
  215.     (initget (+ 1 2))
  216.     (setq z (getdist "\nDistancia entre niveles (   ): "))
  217.     )
  218.   )
  219.   (setvar "BLIPMODE" 0)
  220.  
  221.   (setq c 1)
  222.   (setq el (entlast))                 ; Reference entity
  223.   (setq en (entnext el))
  224.   (while (not (null en))
  225.     (setq el en)
  226.     (setq en (entnext el))
  227.   )
  228.  
  229.   ;; Copy the selected entities one level at a time
  230.   (while (< c nl)
  231.     (command "_.COPY" ss "" "0,0,0" (append (list 0 0) (list (* c z)))
  232.     )
  233.     (setq c (1+ c))
  234.   )
  235.  
  236.   (setq ss2 (ssadd))                  ; create a new selection set
  237.   (setq e (entnext el))               ; of all the new entities since
  238.   (while e                            ; the reference entity.
  239.     (ssadd e ss2)
  240.     (setq e (entnext e))
  241.   )
  242.  
  243.   ;; Array original selection set and copied entities
  244.   (cond
  245.     ((= flag 1) (command "_.ARRAY" ss ss2 "" "_R" nr "1" y))
  246.     ((= flag 2) (command "_.ARRAY" ss ss2 "" "_R" "1" nc x))
  247.     ((= flag 3) (command "_.ARRAY" ss ss2 "" "_R" nr nc y x))
  248.   )
  249. )
  250.  
  251. ;;;***************************** MAIN PROGRAM ****************************
  252.  
  253. (defun C:3DARRAY (/ olderr ss xx undo_setting)
  254.   (if (and (= (getvar "cvport") 1) (= (getvar "tilemode") 0))
  255.     (progn
  256.       (prompt "\n *** Comando no permitido en Espacio papel ***\n")
  257.       (princ)
  258.     )
  259.     (progn
  260.       (setq olderr *error*
  261.             *error* 3daerr
  262.       )
  263.       (modes '(;|MSG0|;"cmdecho" "blipmode" "highlight" "orthomode" 
  264.                "ucsfollow" "gridmode")
  265.       )
  266.       (setvar "CMDECHO" 0)
  267.  
  268.       (ai_undo_on)                    ; Turn UNOD on
  269.  
  270.       (command "_.UNDO" "_GROUP")
  271.       (graphscr)
  272.  
  273.       (setq ss nil)
  274.       (while  (null ss)               ; Ensure selection of entities
  275.         (setq ss (ai_ssget (ssget)))
  276.       )
  277.     
  278.       (initget 1 "Rectangular Polar Circular")
  279.       (setq xx (getkword "\nMatriz Rectangular o Polar (R/P): "))
  280.       (cond 
  281.         ((eq xx "Rectangular") 
  282.           (r-array)
  283.         )
  284.         (T 
  285.           (p-array)
  286.         )
  287.       )
  288.       (command "_.UNDO" "_E")
  289.       (ai_undo_off)                   ; Return UNDO to initial state
  290.       (moder)                         ; Restore system variables
  291.       (setq *error* olderr)           ; Restore old *error* handler
  292.       (princ)
  293.     )
  294.   )
  295. )
  296.  
  297. (princ "  3DARRAY cargada.")
  298. (princ)
  299.