home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SAMPLE / XDATA.LSP < prev   
Encoding:
Lisp/Scheme  |  1995-02-08  |  17.3 KB  |  499 lines

  1. ; Next available MSG number is    68 
  2. ; MODULE_ID XDATA_LSP_
  3. ;;;---------------------------------------------------------------------------;
  4. ;;;
  5. ;;;    XDATA.LSP
  6. ;;;    
  7. ;;;    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994 by Autodesk, Inc.
  8. ;;;
  9. ;;;    Permission to use, copy, modify, and distribute this software
  10. ;;;    for any purpose and without fee is hereby granted, provided
  11. ;;;    that the above copyright notice appears in all copies and
  12. ;;;    that both that copyright notice and the limited warranty and
  13. ;;;    restricted rights notice below appear in all supporting
  14. ;;;    documentation.
  15. ;;;
  16. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  17. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  18. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  19. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  20. ;;;    UNINTERRUPTED OR ERROR FREE.
  21. ;;;
  22. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  23. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  24. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  25. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  26. ;;;
  27. ;;;.
  28. ;;;  
  29. ;;;---------------------------------------------------------------------------;
  30. ;;;  DESCRIPTION
  31. ;;;
  32. ;;;   XDATA
  33. ;;;
  34. ;;;   Program that attaches extended data types to a selected entity.  
  35. ;;;
  36. ;;;   After selecting an entity and entering an application name for the 
  37. ;;;   extended data, the following types of extended data are prompted for:
  38. ;;;
  39. ;;;    1)  An ASCII string up to 255 bytes long (group code 1000).
  40. ;;;    2)  A layer name (group code 1003).
  41. ;;;    3)  An entity handle (group code 1005).
  42. ;;;    4)  3 real numbers (group code 1010).
  43. ;;;    5)  A 3D World space position (group code 1011).
  44. ;;;    6)  A 3D World space displacement (group code 1012).
  45. ;;;    7)  A 3D World space direction (group code 1013).
  46. ;;;    8)  A real number (group code 1040).
  47. ;;;    9)  A distance (group code 1041).
  48. ;;;   10)  A scale factor (group code 1042).
  49. ;;;   11)  A 16-bit integer (group code 1070).
  50. ;;;   12)  A 32-bit signed long integer (group code 1071).
  51. ;;;
  52. ;;;   Numbers 5, 6, 7, 9 and 10 are "transformable" data types, and
  53. ;;;   are either moved, scaled, rotated or mirrored along with the parent
  54. ;;;   entity, or possibly some combination of these, depending on the
  55. ;;;   group code and the nature of the operation on the parent entity.
  56. ;;;
  57. ;;;   Binary data chunks (group code 1004) are not supported. 
  58. ;;;
  59. ;;;
  60. ;;;   XDLIST
  61. ;;;
  62. ;;;   Program that lists the Xdata associated with an application for the
  63. ;;;   selected entity.
  64. ;;; 
  65. ;;;   For a complete description of extended data types see the "AutoCAD 
  66. ;;;   Reference Manual."
  67. ;;;
  68. ;;;---------------------------------------------------------------------------;
  69.  
  70.  
  71. ;;;---------------------------------------------------------------------------;
  72. ;;; Internal error handling.
  73. ;;;---------------------------------------------------------------------------;
  74.  
  75. (defun xdataerr(s)
  76.   (if (/= s "Funci≤n cancelada")
  77.     (princ (strcat "\nError: " s))
  78.   )
  79.   (setq *error* olderr) 
  80.   (if ename (redraw ename 4))         ; de-highlight entity
  81.   (princ)
  82. )
  83.  
  84. ;;;---------------------------------------------------------------------------;
  85. ;;; Get user input.
  86. ;;;---------------------------------------------------------------------------;
  87.  
  88. (defun getinput (/ cont esel)
  89.  
  90.   ;; Forces selection of an entity and sets ename to the name of the  
  91.   ;; selected entity.
  92.  
  93.   (while
  94.     (not (setq esel (entsel)))
  95.   )
  96.             
  97.   (if (= which 1)                     ; If XDATA() is happening...
  98.     (progn
  99.       (setq ename (car esel))         ; Get entity info...
  100.       (redraw ename 3)                ; ...highlight entity
  101.       (setq elist (entget ename (list "*"))) ; ...including xdata for all 
  102.                                       ; registered applications.    
  103.             
  104.       ;; Force the entry of a registered application name (group code 1001).
  105.    
  106.       (setq cont T)
  107.       (while cont 
  108.         (setq rname (xstrcase (getstring "\nNombre de la aplicaci≤n: ")))
  109.         (if (/= rname "") 
  110.           (setq cont nil)
  111.         )
  112.       )
  113.     )
  114.   )
  115.   (if (= which 2)                     ; If XDPRINT() is happening...
  116.     (progn                           
  117.       (setq ename (car esel))         ; Get entity info
  118.       (redraw ename 3)                ; ...highlight entity  
  119.       (setq rname (xstrcase (getstring "\nNombre de la aplicaci≤n <*>: ")))
  120.       (if (= rname "")                ; If null input, get all.
  121.         (setq rname "*")
  122.       )                   
  123.       (setq elist (entget ename (list rname))) 
  124.     ) 
  125.   )
  126. )
  127.  
  128. ;;;---------------------------------------------------------------------------;
  129. ;;; Get user values for extended entity data and build XD_LIST.
  130. ;;;---------------------------------------------------------------------------;
  131.  
  132. (defun getdata (/ xd_type)
  133.  
  134.   (setq xflag 0)
  135.  
  136.   ;; Check whether the selected entity has some extended data already.
  137.  
  138.   (if (assoc -3 elist)
  139.     (progn
  140.       (setq size_old (xdsize (assoc -3 elist)))
  141.       (princ "\nEl objeto tiene ") 
  142.       (princ size_old )
  143.       (princ " bytes de Xdata - se a±adirßn nuevos Xdata.\n")
  144.     )
  145.   )
  146.  
  147.   (setq xd_list (list '(1002 . "}"))) ; Initialize list of xdata for this app.
  148.  
  149.   (setq xd_type T)                    ; Initialize loop terminator.
  150.  
  151.   (while (not (or (eq xd_type "Salir") (eq xd_type "Salir") (eq xd_type nil)))
  152.     (setq hand (getvar "handles"))
  153.     (initget                          ; Initialize keyword list.
  154.       (strcat "cAdena Capa 3real desPlazamiento pOsici≤n Identificador"
  155.             " Direcci≤n Real disTancia Escala"
  156.             " eNtero Long Salir"
  157.  
  158.       )
  159.     )     
  160.     
  161.     (setq xd_type (getkword (strcat   ; Prompt user to select keyword.
  162.        "\n3real/Dir/desP/disT/Ident/eNt/Capa/Long/pOs/Real/Escala/cAdena/<Salir>: "))
  163.     )
  164.  
  165.     ;; Add sub-list to xdata list.
  166.  
  167.     (cond
  168.       ((eq xd_type "3real")
  169.         (if (/= (setq input (getpoint "\n3 n·meros reales: ")) nil)  
  170.            (setq xd_list (cons (cons 1010 input) xd_list))
  171.         )    
  172.       )
  173.       ((eq xd_type "Direcci≤n")
  174.         (if (/= (setq input (getpoint "\nDirecci≤n en SCU 3D: ")) nil)
  175.           (setq xd_list (cons (cons 1013 input) xd_list))
  176.         )      
  177.       )
  178.       ((eq xd_type "desPlazamiento")
  179.         (if (/= (setq input (getpoint "\nDesplazamiento en SCU 3D: ")) nil)  
  180.           (setq xd_list (cons (cons 1012 input) xd_list))
  181.         )
  182.       )
  183.       ((eq xd_type "disTancia")
  184.         (if (/= (setq input (getdist "\nDistancia: ")) nil) 
  185.           (setq xd_list (cons (cons 1041 input) xd_list))
  186.         )
  187.       )
  188.       ((eq xd_type "Identificador")
  189.         (if (or ( = (setq hand (getstring "\nIdentificador de base de datos: ")) "0")
  190.                 (handent hand) 
  191.             )
  192.           (setq xd_list (cons (cons 1005 hand) xd_list))
  193.           (if (/= hand "") 
  194.             (princ "\nIdentificador no vßlido - el identificador debe existir o tener el valor 0.")
  195.           )
  196.         )         
  197.       )
  198.       ;; Values entered greater than 32767 cause AutoLISP to issue an
  199.       ;; error message stating "Value must be between -32767 and 32767. "
  200.       ;; Values less than 0 are trapped out by the (initget).  Though the 
  201.       ;; message may be confusing, the values are always correct.  This is
  202.       ;; an AutoLISP limitation.
  203.       ((eq xd_type "eNtero")
  204.         (initget 4)
  205.         (if (/= (setq input (getint "\nN║ entero de 16 bits: ")) nil)
  206.           (setq xd_list (cons (cons 1070 input) xd_list))
  207.         )
  208.       )  
  209.       ((eq xd_type "Capa")
  210.         (setq input (getstring "\nNombre de capa: "))
  211.         (if (tblsearch ;|MSG0|;"layer" input)
  212.           (setq xd_list (cons (cons 1003 input) xd_list))
  213.           (if (/= input "")
  214.             (princ "\nNombre de capa no vßlido - la capa debe existir.")
  215.           )
  216.         ) 
  217.       )
  218.       ((eq xd_type "Long")
  219.         (if (/= (setq input (getint "\nN║ entero de 32 bits con signo: ")) nil)
  220.           (setq xd_list (cons (cons 1071 input) xd_list))
  221.         )
  222.       )
  223.       ((eq xd_type "pOsici≤n")
  224.         (if (/= (setq input (getpoint "\nPosici≤n en el espacio SCU 3D: ")) nil) 
  225.           (setq xd_list (cons (cons 1011 input) xd_list))
  226.         )    
  227.       )
  228.       ((eq xd_type "Real")
  229.         (if (/= (setq input (getreal "\nN·mero real: ")) nil) 
  230.           (setq xd_list (cons (cons 1040 input) xd_list))
  231.         ) 
  232.       )
  233.       ((eq xd_type "Escala")
  234.         (if (/= (setq input (getreal "\nFactor de escala: ")) nil)
  235.           (setq xd_list (cons (cons 1042 input) xd_list))
  236.         )
  237.       )
  238.       ((eq xd_type "cAdena")
  239.         (setq xd_list (cons (cons 1000 (getstring T 
  240.           "\nCadena ASCII: ")) xd_list))
  241.       )
  242.       (t)
  243.     )
  244.   )
  245.  
  246.   ;; Was any xdata entered besides a registered application name ??
  247.  
  248.   (setq xflag (length xd_list))
  249.  
  250.   ;; Append opening brace to front of xdata list.
  251.  
  252.   (setq xd_list (cons '(1002 . "{") xd_list))
  253.  
  254.   ;; Append application name to front of xdata list.
  255.  
  256.   (setq xd_list (cons rname xd_list))
  257.  
  258.   ;; Append -3 group code to front of list containing xdata list.
  259.  
  260.   (setq xd_list (list -3 xd_list))
  261.  
  262.   ;; Find the total size of the new xdata. 
  263.  
  264.   (setq size_new (xdsize xd_list))
  265. )
  266.  
  267.  
  268. ;-----------------------------------------------------------------------------;
  269. ; XDATA
  270. ;-----------------------------------------------------------------------------;
  271.  
  272. (defun c:xdata (/ all elist ename old olderr new rname size_new xd_list
  273.                   xd_list1 xd_list2 xd_list3 xd_ent regflag hand xflag
  274.                   size_old which)
  275.  
  276.   
  277.  
  278.   (setq olderr *error*                ; Use special error handling function.
  279.         *error* xdataerr)
  280.  
  281.   (setq which 1)                      ; Flag for (getinput)  
  282.  
  283.   (setq regflag 0)                    ; Regapp flag.
  284.  
  285.   (getinput)                          ; Prompt for user input
  286.  
  287.   (redraw ename 4)                    ; De-highlight entity 
  288.  
  289.     
  290.  
  291.   (if (regapp rname)                  ; Register the application name.
  292.     (princ (strcat "\n" rname " nueva aplicaci≤n.\n"))
  293.     (princ (strcat "\nAplicaci≤n " rname " ya registrada.\n"))
  294.   )
  295.  
  296.   ;; Prompt for user values for xdata and build xdata list XD_LIST.
  297.  
  298.   (getdata)
  299.  
  300.   ;; The extended data list is now added to the entity data.  This is a
  301.   ;; little more involved if the entity already has extended data.  A check
  302.   ;; of available Xdata space must be made too.
  303.  
  304.   (if (< size_new (xdroom ename))     ; If there is room for more...
  305.     (progn     
  306.       (if (assoc -3 elist)            ; and contains xdata already...
  307.         (progn                                            
  308.           (setq xd_list (cdr xd_list)) ; New xdata.
  309.           (setq xd_ent (cdr (assoc -3 elist))) ; Old xdata.
  310.           ;; Find old xdata with same regapp
  311.           (if (setq old (cddr (assoc rname xd_ent))) 
  312.             (progn                                    
  313.               (setq regflag 1)              
  314.               (setq new (cdr (reverse (cddr (assoc rname xd_list)))))
  315.               (setq all (append new old)) ; Join old and new xdata with 
  316.                                       ; same application name.
  317.               (setq xd_list1 (cons (cons 1002 "{") all)) ; Add open curly
  318.               (setq xd_list2 (cons rname xd_list1)) ; Add regapp
  319.              
  320.               ;; Substitute back into existing xdata list.
  321.              
  322.               (setq xd_list3 (subst xd_list2 (assoc rname xd_ent) 
  323.                                              (assoc -3 elist))) 
  324.            )
  325.             (progn                    ; This is a new regapp...
  326.               (setq xd_list (append xd_ent xd_list)) ; Joins xdata.
  327.               (setq xd_list3 (cons -3 xd_list))
  328.             )
  329.           )
  330.           (setq elist (subst xd_list3 (assoc -3 elist) elist)) ; Joins entity
  331.         )  
  332.         (setq elist (cons xd_list elist)) ; No xdata yet.
  333.       )
  334.       
  335.     )
  336.     (princ (strcat "\nEspacio insuficiente para Xdata en el objeto"
  337.                    "- no se han a±adido nuevos Xdata.")
  338.     )
  339.   )
  340.  
  341.   ;; Finally update the entity in the database to contain the new xdata.
  342.  
  343.   (if (entmod elist)     
  344.     (if (and (= 1 regflag) (<= xflag 1))   ; old application name     
  345.       (princ "\nNo se han a±adido Xdata.")  
  346.       (princ "\nSe han a±adido nuevos Xdata.") 
  347.     )
  348.   )
  349.  
  350.   (setq *error* olderr)               ; Reset the error function.
  351.   (redraw ename 4)                    ; Dehighlight entity.
  352.  
  353.   (prin1)
  354. )
  355.  
  356. ;;;---------------------------------------------------------------------------;
  357. ;;;  XDLIST
  358. ;;;---------------------------------------------------------------------------;
  359.  
  360. (defun C:XDLIST (/ linecount xd_list app_list app_sub_list xd_code
  361.                    xd_data rname elist ename)
  362.  
  363.   (setq olderr *error*                ; Redefine error handler.
  364.         *error* xdataerr)
  365.  
  366.   (setq which 2)                      ; Flag for (getinput)
  367.  
  368.   (getinput)                          ; Get user input. 
  369.  
  370.   (redraw ename 4)                    ; De-highlight entity.
  371.  
  372.   ;; See if there's any xdata in the selected entity associated with the
  373.   ;; application name.
  374.  
  375.   (if (not (setq xd_list (assoc -3 elist)))
  376.     (progn  
  377.       (princ "\nNo hay Xdata asociados con el nombre de la aplicaci≤n.")
  378.     )
  379.     (setq xd_list (cdr xd_list))      ; Strip -3 from xd_list
  380.   )
  381.  
  382.   (setq linecount 0)                  ; # of lines printed
  383.  
  384.   (while xd_list                      ; There's any xdata left...
  385.     (setq app_list (car xd_list))           
  386.     (textscr)
  387.     (princ "\n\n* Nombre de aplicaci≤n registrado: ")
  388.     (princ (car app_list))
  389.     (setq app_list (cdr app_list))    ; Strip app name
  390.     (while app_list
  391.       (setq app_sub_list (car app_list))  ; Get sub list
  392.       (setq xd_code (car app_sub_list))   ; Get group code
  393.       (setq xd_data (cdr app_sub_list))   ; Get data
  394.  
  395.       ;; Conditions for all group codes.
  396.       ;; Prints 'em all except binary chunks.
  397.       (cond
  398.         ((= 1000 xd_code)
  399.           (princ "\n* C≤digo 1000, cadena ASCII: ")
  400.           (princ xd_data)
  401.         )
  402.         ((= 1001 xd_code)
  403.           (princ "\n* C≤digo 1001, nombre de aplicaci≤n registrado: ")
  404.           (princ xd_data)
  405.         )
  406.         ((= 1002 xd_code)
  407.           (princ "\n* C≤digo 1002, corchete abierto o cerrado: ")
  408.           (princ xd_data)
  409.         )
  410.         ((= 1003 xd_code)
  411.           (princ "\n* C≤digo 1003, nombre de capa: ")
  412.          (princ xd_data)
  413.         )
  414.         ((= 1004 xd_code)
  415.           (princ "\n* C≤digo 1004, datos binarios no impresos.")
  416.         )
  417.         ((= 1005 xd_code)
  418.           (princ "\n* C≤digo 1005, identificador de base de datos: ")
  419.           (princ xd_data)
  420.         )
  421.         ((= 1010 xd_code)
  422.           (princ "\n* C≤digo 1010, 3 n·meros reales: ")
  423.           (princ (strcat "("
  424.                  (rtos (car xd_data)) " " 
  425.                  (rtos (cadr xd_data)) " "
  426.                  (rtos (caddr xd_data)) ")"))
  427.         )
  428.         ((= 1011 xd_code)
  429.           (princ "\n* C≤digo 1011, posici≤n en SCU 3D: ")
  430.           (princ (strcat "("
  431.                  (rtos (car xd_data)) " "
  432.                  (rtos (cadr xd_data)) " "
  433.                  (rtos (caddr xd_data)) ")"))
  434.         )
  435.         ((= 1012 xd_code)
  436.           (princ "\n* C≤digo 1012, desplazamiento en SCU 3D: ")
  437.           (princ (strcat "("
  438.                  (rtos (car xd_data)) " "
  439.                  (rtos (cadr xd_data)) " "
  440.                  (rtos (caddr xd_data)) ")"))
  441.         )
  442.         ((= 1013 xd_code)
  443.           (princ "\n* C≤digo 1013, direcci≤n en SCU 3D: ")
  444.           (princ (strcat "("
  445.                  (rtos (car xd_data)) " "
  446.                  (rtos (cadr xd_data)) " "
  447.                  (rtos (caddr xd_data)) ")"))
  448.         )
  449.         ((= 1040 xd_code)
  450.           (princ "\n* C≤digo 1040, n·mero real: ")
  451.           (princ (rtos xd_data))
  452.         )
  453.         ((= 1041 xd_code)
  454.           (princ "\n* C≤digo 1041, distancia: ")
  455.           (princ (rtos xd_data))
  456.         )
  457.         ((= 1042 xd_code)
  458.           (princ "\n* C≤digo 1042, factor de escala: ")
  459.           (princ (rtos xd_data))
  460.         )
  461.         ((= 1070 xd_code)
  462.           (princ "\n* C≤digo 1070, n║ entero de 16 bits: ")
  463.           (princ xd_data)
  464.         )
  465.         ((= 1071 xd_code)
  466.           (princ "\n* C≤digo 1071, n║ entero de 32 bits con signo: ")
  467.           (princ (rtos xd_data 2 0))
  468.         )
  469.         (t 
  470.           (princ "\n* C≤digo de Xdata desconocido: ") 
  471.           (princ xd_code)
  472.           (princ " *")
  473.         )
  474.       )
  475.       (setq app_list (cdr app_list))
  476.       (setq linecount (1+ linecount))
  477.       (if (>= linecount 20)           ; Pause at 20 lines printed.
  478.         (progn
  479.           (getstring "\n-mßs-")
  480.           (setq linecount 0)
  481.         )
  482.       )
  483.     )  
  484.   (setq xd_list (cdr xd_list))        ; Get next xdata list.
  485. )  
  486.   
  487.  
  488.   (princ "\n\nEl objeto tiene ")                     
  489.   (princ (xdroom ename))              ; Figure how much room is left.
  490.   (princ " bytes de espacio Xdata disponible.")
  491.  
  492.   (setq *error* olderr)               ; Reset the error function.
  493.   (prin1)                             ; Quiet exit.
  494.  
  495. )
  496. ;;;---------------------------------------------------------------------------;
  497. (princ "\nC:XDATA cargada. Teclee XDATA y XDLIST para definir y ver datos. ")
  498. (princ)
  499.