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

  1. ; Next available MSG number is    22 
  2. ; MODULE_ID DDINSERT_LSP_
  3. ;;;
  4. ;;;    ddinsert.lsp
  5. ;;;
  6. ;;;    Copyright (C) 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. ;;;   DESCRIPTION
  28. ;;;
  29. ;;;   An AutoLISP implementation of the AutoCAD INSERT command with a dialogue
  30. ;;;   interface.  Answers the oft requested feature of being able to select
  31. ;;;   at Insert time either an internal or external drawing.
  32. ;;;
  33. ;;;   The user is presented with a dialogue allowing the selection from nested
  34. ;;;   dialogues of either an internal or external block.  Edit fields can be
  35. ;;;   used to enter or preset the insertion point, scale, and rotation angle,
  36. ;;;   or alternatively, these can be set dynamically as in the INSERT command.
  37. ;;;
  38. ;;;   
  39. ;;;----------------------------------------------------------------------------
  40. ;;;   Prefixes in command and keyword strings: 
  41. ;;;      "."  specifies the built-in AutoCAD command in case it has been           
  42. ;;;           redefined.
  43. ;;;      "_"  denotes an AutoCAD command or keyword in the native language
  44. ;;;           version, English.
  45. ;;;
  46. ;;;----------------------------------------------------------------------------
  47. ;;;
  48. ;;; ===========================================================================
  49. ;;; ===================== load-time error checking ============================
  50. ;;;
  51.  
  52.   (defun ai_abort (app msg)
  53.      (defun *error* (s)
  54.         (if old_error (setq *error* old_error))
  55.         (princ)
  56.      )
  57.      (if msg
  58.        (alert (strcat " Error en la aplicaci≤n: "
  59.                       app
  60.                       " \n\n  "
  61.                       msg
  62.                       "  \n"
  63.               )
  64.        )
  65.      )
  66.      (exit)
  67.   )
  68.  
  69. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  70. ;;; and then try to load it.
  71. ;;;
  72. ;;; If it can't be found or it can't be loaded, then abort the
  73. ;;; loading of this file immediately, preserving the (autoload)
  74. ;;; stub function.
  75.  
  76.   (cond
  77.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  78.  
  79.      (  (not (findfile ;|MSG0|;"ai_utils.lsp"))                     ; find it
  80.         (ai_abort "DDINSERT"
  81.                   (strcat "Imposible localizar el archivo AI_UTILS.LSP."
  82.                           "\n Compruebe el directorio de soporte.")))
  83.  
  84.      (  (eq ;|MSG0|;"failed" (load "ai_utils" ;|MSG0|;"failed"))      ; load it
  85.         (ai_abort "DDINSERT" "Imposible cargar el archivo AI_UTILS.LSP"))
  86.   )
  87.  
  88.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  89.       (ai_abort "DDINSERT" nil)         ; a Nil <msg> supresses
  90.   )                                    ; ai_abort's alert box dialog.
  91.  
  92. ;;; ==================== end load-time operations ===========================
  93.  
  94.  
  95. ;;;----------------------------------------------------------------------------
  96. ;;;  The main dialogue.
  97. ;;;----------------------------------------------------------------------------
  98. (defun c:ddinsert(/  
  99.                      $value           do_insert      old_cmd            x_pt       
  100.                      blk_exists       do_selection   parse_path         x_scale    
  101.                      blk_name         error_msg      pat                y_pt     
  102.                      blk_name1        explode        path_name          y_scale  
  103.                      bl_match         ex_name        path_name_exist1   z_pt    
  104.                      bl_name          error_scale    pat_match          z_scale 
  105.                      check_current    globals        redefine         
  106.                      check_fd         good_value     reset            
  107.                      check_i          ins_name       rotation         
  108.                      check_input      int_blocks     range
  109.                      check_name       ins_var                     
  110.                      check_name_ok    just_name      table_item 
  111.                      cmd              list1                 
  112.                                       list_blocks    table_name       
  113.                      dcl_id           n              use_val          
  114.                      ddinsert_main    name           use_val_tog      
  115.                                       n_name         value            
  116.                                                      what_next        
  117.                   )
  118.                                                                                   
  119.   ;;
  120.   ;; Routine that inserts the selected block.
  121.   ;;
  122.   (defun do_insert()
  123.     (cond
  124.       ((= 1 on_screen)
  125.         (command "_.insert" ins_name)
  126.       )
  127.       ((and (= 0 on_screen) (= 0 explode))
  128.         (command "_.insert" ins_name (list x_pt y_pt z_pt)
  129.                  ;|MSG0|;"_xyz" x_scale y_scale z_scale rotation)
  130.       )
  131.       ((and (= 0 on_screen) (= 1 explode))
  132.         (command "_.insert" ins_name (list x_pt y_pt z_pt)
  133.                  x_scale rotation)
  134.       )
  135.       (T (princ "error de programaci≤n en do_insert"))
  136.     )
  137.   )  
  138.   ;;
  139.   ;;  Call routine to display nested dialogue.  Set edit box to returned value
  140.   ;;  if not nil.
  141.   ;;
  142.   (defun int_blocks()
  143.     (list_blocks)
  144.     (if blk_name1 
  145.       (progn
  146.         (set_tile ;|MSG0|;"current_name" (setq blk_name (xstrcase blk_name1)))
  147.         (set_tile ;|MSG0|;"path_name" "")
  148.       )
  149.     )
  150.   )
  151.   ;;
  152.   ;; Short hand error tile resetting.
  153.   ;;
  154.   (defun reset()
  155.     (set_tile ;|MSG0|;"error" "")
  156.   )
  157.   ;;
  158.   ;; Check does the block exist, either internally or externally.
  159.   ;;
  160.   (defun check_current()
  161.     (setq blk_name (xstrcase (ai_strtrim (get_tile ;|MSG0|;"current_name"))))     
  162.     (setq path_name (ai_strtrim (get_tile ;|MSG0|;"path_name")))
  163.     (if (and (> (strlen blk_name) 3)    ; strip ".dwg" if necessary
  164.              (= (substr blk_name (- (strlen blk_name) 3)) ;|MSG0|;".DWG")
  165.         )
  166.       (setq blk_name (substr blk_name 1 (- (strlen blk_name) 4)))
  167.     )
  168.     (cond
  169.       ;; Length less 32.
  170.       ((not (snvalid blk_name))
  171.         (set_tile "error" "Nombre de bloque no vßlido.")
  172.       )
  173.       ;; if the block exists in the drawing (necessary for logand).
  174.       ((and (setq xcheck (tblsearch ;|MSG0|;"block" blk_name))
  175.             (not (zerop (logand 52 (cdr (assoc 70 xcheck)))))
  176.        )
  177.         (set_tile "error" "Error - Imposible insertar una RefX. Utilice RefX Enlazar.")
  178.       )
  179.       ;; If the block is undefined give message.
  180.       ((and (= "" path_name)
  181.             (/= "" blk_name)
  182.             (not (member blk_name table_list))
  183.        )
  184.         (set_tile "error" "Nombre de bloque no vßlido.")
  185.       ) 
  186.       ((and (= "" path_name)
  187.             (= "" blk_name)
  188.        )
  189.         (set_tile "error" "Nombre de bloque no vßlido.")
  190.       ) 
  191.       ((not (or (member blk_name table_list) ; does name exist as an internal
  192.                  (findfile path_name) ; or external block ??
  193.             )
  194.        )
  195.         (set_tile "error" "Nombre de bloque no vßlido.")
  196.       )  
  197.       (t)  
  198.     )
  199.   ) 
  200.   ;;
  201.   ;; Check all input via a cond.  If any error exists, display the relevant 
  202.   ;; message. If no errors bring down the dialogue.
  203.   ;;
  204.   (defun check_name_ok(/ ex_found)
  205.     (setq blk_name (xstrcase (ai_strtrim (get_tile ;|MSG0|;"current_name"))))
  206.     (setq path_name (ai_strtrim (get_tile ;|MSG0|;"path_name")))
  207.     ;; Check to see if the path name is valid once here.
  208.     (if (findfile path_name) (setq ex_found 1))
  209.  
  210.     ;; It's acceptable for the user to type in a drawing name without
  211.     ;; entering a Block name in the Block field.  If there is a valid pathname
  212.     ;; and an empty block name field, use parse path to get the block name 
  213.     ;; from the drawing name.
  214.     (if (and (= 1 ex_found) (= "" blk_name)) (parse_path))
  215.  
  216.     (setq redefine 1)
  217.     ;; Check once here to see if the block name already exists in the drawing.
  218.     (setq xcheck (tblsearch ;|MSG0|;"block" blk_name))
  219.  
  220.     (cond 
  221.       ((and (= "" path_name)             ; Internal
  222.             (member blk_name table_list) 
  223.             (= 0 explode)                ; explode off
  224.        )
  225.         (setq ins_name blk_name)
  226.       ) 
  227.       ((and (= "" path_name)             ; Internal
  228.             (member blk_name table_list) 
  229.             (= 1 explode)                ; explode on
  230.        )
  231.         (setq ins_name (strcat "*" blk_name))
  232.       ) 
  233.       ((and (= 1 ex_found)               ; External
  234.             (= explode 1)                ; Explode on
  235.        )
  236.         (setq ins_name (strcat "*" path_name)) 
  237.       )
  238.       ((and (= 1 ex_found)                       ; External
  239.             (check_name blk_name)                ; blk name valid
  240.             (not xcheck)                         ; unique 
  241.         ) 
  242.         (setq ins_name (strcat blk_name "=" path_name))  
  243.       )
  244.       ((and (= 1 ex_found)                                ; External
  245.             xcheck
  246.             (zerop (logand 53 (cdr (assoc 70 xcheck))))   ; Not an Xref
  247.             (blk_exists)                                  ; redefine yes
  248.        )                        
  249.         (setq ins_name (strcat blk_name "=" path_name))  
  250.       )
  251.       (T  
  252.         (cond 
  253.           ((not redefine)
  254.           )
  255.           ((and xcheck
  256.                 (not (zerop (logand 53 (cdr (assoc 70 xcheck))))) ; is an Xref
  257.            )
  258.             (set_tile ;|MSG0|;"error" 
  259.                       "Error - Imposible insertar una RefX. Utilice RefX Enlazar."
  260.             ) 
  261.             ;; if the path_name in not "" set focus there on error.
  262.             (if (read path_name)
  263.               (mode_tile ;|MSG0|;"path_name" 2)
  264.               (mode_tile ;|MSG0|;"current_name" 2)
  265.             )
  266.           )
  267.           ((= "" path_name) 
  268.             (set_tile "error" "Nombre de bloque no vßlido.")
  269.             (mode_tile ;|MSG0|;"current_name" 2)
  270.           )
  271.           ((and (/= "" path_name) (not (findfile path_name)))
  272.             (set_tile "error" "Nombre de archivo no vßlido.")
  273.             (mode_tile ;|MSG0|;"path_name" 2)
  274.           )
  275.           ((and (/= "" path_name) (findfile path_name))
  276.             (set_tile "error" "Nombre de bloque no vßlido.")
  277.             (mode_tile ;|MSG0|;"current_name" 2)
  278.           )
  279.           (T (princ "Error al comprobar el nombre de bloque."))
  280.         )
  281.         nil 
  282.       )
  283.     )
  284.   )
  285.   ;; 
  286.   ;;  On OK all input is checked before the dialogue is dismissed.
  287.   ;;
  288.   (defun check_input()
  289.     (if (= 1 explode)
  290.       (progn
  291.         (setq range 6)                 ; non zero & non negative
  292.         (setq error_scale "La escala X debe ser positiva y distinta de cero.")
  293.       )
  294.       (progn
  295.         (setq range 2)                 ; non zero
  296.         (setq error_scale "La escala X no puede ser igual a cero.")
  297.       )
  298.     )
  299.     (cond
  300.       ((not (check_name_ok)))
  301.       ((and (= 0 on_screen) (bad_xyzxr)))          ; check insert point coords.
  302.       ((and (= 0 on_screen)        ; check scale if explode is off
  303.             (= 0 explode)
  304.             (bad_yz)
  305.       ))
  306.       (t (done_dialog 1))           ; if all is well, bring down the dialogue.
  307.     ) 
  308.   )
  309.   ;; 
  310.   ;; Check some input and set focus on error.  Return nil is nothing bad.
  311.   ;;
  312.   (defun bad_xyzxr()
  313.     (cond 
  314.       ((not (setq x_pt (ai_num (get_tile ;|MSG0|;"x_pt") "Coordenada X no vßlida." 0)))
  315.         (mode_tile ;|MSG0|;"x_pt" 2)
  316.       )
  317.       ((not (setq y_pt (ai_num (get_tile ;|MSG0|;"y_pt") "Coordenada Y no vßlida" 0)))
  318.         (mode_tile ;|MSG0|;"y_pt" 2)
  319.       )
  320.       ((not (setq z_pt (ai_num (get_tile ;|MSG0|;"z_pt") "Coordenada Z no vßlida." 0)))
  321.         (mode_tile ;|MSG0|;"z_pt" 2)
  322.       )
  323.       ((not (setq x_scale (ai_num 
  324.                             (get_tile ;|MSG0|;"x_scale") error_scale range)))
  325.         (mode_tile ;|MSG0|;"x_scale" 2)
  326.       )
  327.       ((not (setq rotation (ai_angle (get_tile ;|MSG0|;"rotation")
  328.                                     "Angulo de rotaci≤n no vßlido." 
  329.                            )
  330.             )
  331.         )
  332.         (mode_tile ;|MSG0|;"rotation" 2)
  333.       )
  334.       (t nil)
  335.     )
  336.   )
  337.   ;;
  338.   ;; Check the Y scale and Z scale.  Return nil if bad.
  339.   ;;
  340.   (defun bad_yz()
  341.     (cond
  342.       ((not (setq y_scale (ai_num (get_tile ;|MSG0|;"y_scale") 
  343.                                   "La escala Y no puede ser igual a cero." 2)))
  344.         (mode_tile ;|MSG0|;"y_scale" 2)
  345.       )
  346.       ((not (setq z_scale (ai_num (get_tile ;|MSG0|;"z_scale") 
  347.                                   "La escala Z no puede ser igual a cero." 2)))
  348.         (mode_tile ;|MSG0|;"y_scale" 2)
  349.       )
  350.     )
  351.   )
  352.   ;;
  353.   ;; If called with 0, display getfiled for a drawing name. If called with 1
  354.   ;; get the string form the edit box.
  355.   ;;
  356.   (defun check_fd (bit)
  357.     (cond
  358.       ((and (= 0 bit)
  359.             (setq ex_name (getfiled "Seleccione archivo de dibujo" "" "dwg" 2))
  360.        )
  361.         (setq path_name ex_name) 
  362.         (check_fd1)
  363.       )
  364.       ((= 1 bit)
  365.         (setq path_name (ai_strtrim (get_tile ;|MSG0|;"path_name")))
  366.         (check_fd1)
  367.       )
  368.     )
  369.   )
  370.  
  371.   (defun check_fd1()
  372.     (cond
  373.       ;; if the length of the name is greater than 4 and the last 4 characters
  374.       ;; are not .dwg, then tag .dwg on.
  375.       ((and (> (strlen path_name) 4)
  376.              (not (= ;|MSG0|;".dwg" 
  377.                      (strcase (substr path_name (- (strlen path_name) 3)) T)
  378.              ))
  379.         )
  380.          (setq path_name (strcat path_name ;|MSG0|;".dwg"))
  381.       )
  382.       ((and (> (strlen path_name) 0)
  383.                  (<= (strlen path_name) 4)
  384.        )
  385.          (setq path_name (strcat path_name ;|MSG0|;".dwg"))
  386.       )
  387.       (t)                             ; name must have .dwg already.
  388.     )
  389.     (cond 
  390.      ( (findfile path_name)           ; check to see if it exists
  391.         (set_tile ;|MSG0|;"path_name" path_name)
  392.         (parse_path)
  393.         (set_tile ;|MSG0|;"current_name" blk_name)
  394.         (check_current)
  395.      )
  396.      ((and (= "" path_name)              ; OK to have a null pathname if the
  397.            (member blk_name table_list)  ; Block name is valid
  398.       )
  399.      )
  400.      (t (set_tile "error" "Nombre de archivo no vßlido."))
  401.     )
  402.   )
  403.   ;;
  404.   ;;  Find dwg name from path name.
  405.   ;;
  406.   (defun parse_path( / a b)
  407.     (setq a 1)
  408.     (repeat (strlen path_name)
  409.       (if (member (substr path_name a 1) '("/" "\\" ":"))
  410.         (setq b a) 
  411.       )
  412.       (setq a (1+ a))
  413.     )
  414.     (if b
  415.       (setq blk_name (strcase (substr path_name (1+ b))))
  416.       (setq blk_name (strcase path_name))
  417.     )
  418.     (if (and (> (strlen blk_name) 3)    ; strip ".dwg" if necessary
  419.              (= (substr blk_name (- (strlen blk_name) 3)) ;|MSG0|;".DWG"))   
  420.         (setq blk_name (substr blk_name 1 (- (strlen blk_name) 4))) 
  421.     )
  422.   )
  423.   ;;
  424.   ;; Enable/Disable for Insertion Point.
  425.   ;;
  426.   (defun on_screen_tog()
  427.     (cond
  428.       ((= 1 on_screen)
  429.         (mode_tile ;|MSG0|;"x_pt" 1)
  430.         (mode_tile ;|MSG0|;"y_pt" 1)
  431.         (mode_tile ;|MSG0|;"z_pt" 1)
  432.         (mode_tile ;|MSG0|;"x_scale" 1)
  433.         (mode_tile ;|MSG0|;"y_scale" 1)
  434.         (mode_tile ;|MSG0|;"z_scale" 1)
  435.         (mode_tile ;|MSG0|;"rotation" 1)
  436.       )
  437.       ((and (= 0 on_screen)(= 0 explode))
  438.         (mode_tile ;|MSG0|;"x_pt" 0)
  439.         (mode_tile ;|MSG0|;"y_pt" 0)
  440.         (mode_tile ;|MSG0|;"z_pt" 0)
  441.         (mode_tile ;|MSG0|;"x_scale" 0)
  442.         (mode_tile ;|MSG0|;"y_scale" 0)
  443.         (mode_tile ;|MSG0|;"z_scale" 0)
  444.         (mode_tile ;|MSG0|;"rotation" 0)
  445.       )
  446.       ((and (= 0 on_screen)(= 1 explode))
  447.         (mode_tile ;|MSG0|;"x_pt" 0)
  448.         (mode_tile ;|MSG0|;"y_pt" 0)
  449.         (mode_tile ;|MSG0|;"z_pt" 0)
  450.         (mode_tile ;|MSG0|;"x_scale" 0)
  451.         (mode_tile ;|MSG0|;"y_scale" 1)
  452.         (mode_tile ;|MSG0|;"z_scale" 1)
  453.         (mode_tile ;|MSG0|;"rotation" 0)
  454.       )
  455.     )
  456.   )
  457.   ;;
  458.   ;; Displays a nested dialogue containing an edit box for wildcards and
  459.   ;; a list box of the defined blocks in the drawing.
  460.   ;;
  461.   (defun list_blocks()    
  462.     (setq bl_match '())
  463.     (if (not (new_dialog ;|MSG0|;"list_blocks" dcl_id)) (exit))
  464.     (if (not pat) (setq pat "*"))
  465.     (set_tile ;|MSG0|;"pattern" pat)
  466.     (pat_match pat)
  467.  
  468.     (action_tile ;|MSG0|;"bl_match"   "(bl_name)")
  469.     (action_tile ;|MSG0|;"pattern"    "(pat_match (setq pat (xstrcase $value)))")
  470.     (action_tile ;|MSG0|;"selection"  "(do_selection)")
  471.     (action_tile ;|MSG0|;"accept"     "(if (check_i)(done_dialog 1))")
  472.     (action_tile ;|MSG0|;"cancel"     "(setq blk_name1 nil)(done_dialog 0)")
  473.  
  474.     (start_dialog)
  475.   )
  476.   ;;
  477.   ;; If a name is typed, check to see if  block with that name exists in the
  478.   ;; drawing.
  479.   ;;
  480.   (defun do_selection()
  481.     (set_tile ;|MSG0|;"bl_match" "")
  482.     (setq blk_name1 (xstrcase (get_tile "selection")))
  483.     (check_i)
  484.   )
  485.   ;;
  486.   ;; Display the selected block name in the edit box.
  487.   ;;
  488.   (defun bl_name()  
  489.     (set_tile ;|MSG0|;"error" "")
  490.     (set_tile ;|MSG0|;"selection" (setq blk_name1 (nth (atoi $value) bl_match)))
  491.   )
  492.   ;;
  493.   ;; Confirms that a block with the entered name exists in the drawing.
  494.   ;;
  495.   (defun check_i()
  496.     (if (member blk_name1 table_list)
  497.       (progn 
  498.         (set_tile ;|MSG0|;"error" "") 
  499.         T
  500.       )
  501.       (progn 
  502.         (set_tile "error" "Nombre de bloque no vßlido.")
  503.         (mode_tile ;|MSG0|;"selection" 2)
  504.         nil
  505.       )
  506.     )
  507.   )
  508.   ;;
  509.   ;; This function displays the block list based on the pattern.
  510.   ;;
  511.   (defun pat_match (pat)
  512.     (setq bl_match '())
  513.     (foreach n table_list
  514.       (if (wcmatch n pat)
  515.         (setq bl_match (cons n bl_match))
  516.       )
  517.     )
  518.     (if (>= (getvar "maxsort") (length bl_match)) ; Alphabetise if greater
  519.       (if bl_match (setq bl_match (acad_strlsort bl_match))) ; than maxsort.
  520.     )
  521.     (start_list ;|MSG0|;"bl_match")
  522.     (mapcar 'add_list bl_match)
  523.     (end_list)
  524.   )
  525.   ;;
  526.   ;;  This function checks the validity of the Block name.  If legitimate, the  
  527.   ;;  Block name is returned, nil otherwise.
  528.   ;;
  529.   (defun check_name(name)
  530.     (if (not (or (not name)
  531.                  (= "" name)        
  532.                  (not (snvalid name))
  533.              )
  534.         )  
  535.       name
  536.     )
  537.   )
  538.   ;;
  539.   ;; Post a message, when focus is changed from new name, stating that a block
  540.   ;; already exists with this name which will be redefined. 
  541.   ;;
  542.   (defun path_name_exist1()
  543.     (if (member n_name table_list)
  544.       (set_tile "error" "Se redefinirß un bloque con este nombre.")
  545.     )
  546.   ) 
  547.   ;;
  548.   ;;  An Alert dialogue, called on OK to get confirmation of redefining block.
  549.   ;;  Return T if redefine and nil if Cancel.
  550.   ;;
  551.   (defun blk_exists()
  552.     (if (not (new_dialog ;|MSG0|;"blk_exists" dcl_id)) (exit))   
  553.     (action_tile ;|MSG0|;"redefine" "(done_dialog 2)")
  554.     (action_tile ;|MSG0|;"cancel" "(done_dialog 0)")
  555.     (if (= (start_dialog) 2)  T (setq redefine nil)) 
  556.   )
  557.  
  558.   ;;
  559.   ;; Update the Y and Z scale when X scale is changed.
  560.   ;;
  561.   (defun up_xscale(/ x_temp)
  562.     (reset)
  563.     (if (= 1 explode)
  564.       (progn
  565.         (setq range 6)                 ; non zero & non negative
  566.         (setq error_scale "La escala X debe ser positiva y distinta de cero.")
  567.       )
  568.       (progn
  569.         (setq range 2)                 ; non zero
  570.         (setq error_scale "La escala X no puede ser igual a cero.")
  571.       )
  572.     )
  573.     (if (setq x_temp (ai_num (get_tile ;|MSG0|;"x_scale") error_scale range))
  574.       (progn 
  575.         (set_tile ;|MSG0|;"y_scale" (rtos x_temp))
  576.         (set_tile ;|MSG0|;"z_scale" (rtos (abs x_temp)))
  577.       )
  578.     )
  579.   )
  580.   ;;
  581.    ;; Put up the dialogue.
  582.   ;;
  583.   (defun ddinsert_main()
  584.   
  585.     (if (not (new_dialog ;|MSG0|;"ddinsert" dcl_id)) (exit))
  586.  
  587.  
  588.     ;; Find the defined blocks in the drawing.
  589.     (setq table_list (ai_table ;|MSG0|;"block" 14)) ; no anonymous, Xrefs or 
  590.                                             ; Xref dependents.
  591.  
  592.     ;; Set up some defaults.
  593.     (setq x_pt 0.0)                     (set_tile ;|MSG0|;"x_pt" (rtos x_pt))             
  594.     (setq y_pt 0.0)                     (set_tile ;|MSG0|;"y_pt" (rtos y_pt))             
  595.     (setq z_pt (getvar "elevation"))    (set_tile ;|MSG0|;"z_pt" (rtos z_pt))             
  596.     (setq x_scale 1.0)                  (set_tile ;|MSG0|;"x_scale" (rtos x_scale))          
  597.     (setq y_scale 1.0)                  (set_tile ;|MSG0|;"y_scale" (rtos y_scale))          
  598.     (setq z_scale 1.0)                  (set_tile ;|MSG0|;"z_scale" (rtos z_scale))          
  599.     (setq rotation 0.0)                 (set_tile ;|MSG0|;"rotation" (angtos rotation))       
  600.  
  601.     ;; If a default exists for the on screen toggle, use it.  Else set the 
  602.     ;; toggle to 1.
  603.     (if (setq on_screen (cadr (assoc ;|MSG0|;"ddinsert" ai_defaults)))
  604.       (set_tile ;|MSG0|;"on_screen" (itoa on_screen))
  605.       (set_tile ;|MSG0|;"on_screen" (itoa (setq on_screen 1)))
  606.     )
  607.     (on_screen_tog)
  608.  
  609.     (set_tile ;|MSG0|;"explode" "0") (setq explode 0)
  610.     ;; If the last insert was of a *block (explode on), then insname
  611.     ;; will have a * in front of the block name.  If the blk_name
  612.     ;; exists within the drawing, then put the name in the block field
  613.     ;; and leave the File field empty, else put the path in the file field
  614.     ;; and the block name in the block field.  In both cases, leave explode off.
  615.     (setq ins_var (getvar "insname"))
  616.     (if (= "*" (substr ins_var 1 1))
  617.       (setq path_name (substr ins_var 2))
  618.       (setq path_name ins_var)
  619.     )
  620.     (parse_path)
  621.     (set_tile ;|MSG0|;"current_name" blk_name)
  622.     (if (member blk_name table_list)
  623.       (set_tile ;|MSG0|;"path_name" (setq path_name ""))
  624.       (set_tile ;|MSG0|;"path_name" path_name)
  625.     )  
  626.  
  627.     (action_tile ;|MSG0|;"int_blocks" "(reset)(int_blocks)") 
  628.     (action_tile ;|MSG0|;"ext_blocks" "(reset)(check_fd 0)") 
  629.     (action_tile ;|MSG0|;"current_name" "(reset)(check_current)")
  630.     (action_tile ;|MSG0|;"path_name" "(reset)(check_fd 1)")
  631.     (action_tile ;|MSG0|;"on_screen" "(reset)(setq on_screen (atoi $value))(on_screen_tog)")
  632.     (setq cmd_coor (strcat "(reset)(ai_num $value \""
  633.                            "Coordenada X no vßlida."
  634.                "\" 0)"))
  635.     (action_tile "x_pt" cmd_coor)
  636.     (setq cmd_coor (strcat "(reset)(ai_num $value \""
  637.                            "Coordenada Y no vßlida"
  638.                "\" 0)")) 
  639.     (action_tile "y_pt" cmd_coor)
  640.     (setq cmd_coor (strcat "(reset)(ai_num $value \""
  641.                            "Coordenada Z no vßlida."
  642.                "\" 0)")) 
  643.     (action_tile "z_pt" cmd_coor)
  644.     (action_tile ;|MSG0|;"x_scale" "(up_xscale)")
  645.     (setq cmd_scale (strcat "(reset)(ai_num $value \""
  646.              "La escala Y no puede ser igual a cero."
  647.              "\" 2)"))
  648.     (action_tile ;|MSG0|;"y_scale" cmd_scale)
  649.  
  650.     (setq cmd_scale (strcat "(reset)(ai_num $value\""
  651.                      "La escala Z no puede ser igual a cero." 
  652.                      "\" 2)")) 
  653.     (action_tile ;|MSG0|;"z_scale" cmd_scale)
  654.  
  655.     (setq cmd_scale (strcat "(reset)(ai_angle $value \"" 
  656.                      "Angulo de rotaci≤n no vßlido."  
  657.                      "\")"))  
  658.     (action_tile ;|MSG0|;"rotation" cmd_scale)
  659.  
  660.     (action_tile ;|MSG0|;"explode" "(setq explode (atoi $value))(on_screen_tog)")
  661.     (action_tile ;|MSG0|;"accept" "(check_input)")
  662.     (action_tile ;|MSG0|;"cancel" "(done_dialog 0)")
  663.     (action_tile ;|MSG0|;"help" "(help \"\" \"ddinsert\")")
  664.  
  665.     (setq what_next (start_dialog))
  666.  
  667.     (if (= 1 what_next) 
  668.       (progn
  669.         (do_insert)
  670.         (if (assoc ;|MSG0|;"ddinsert" ai_defaults)
  671.           (setq ai_defaults (subst (list ;|MSG0|;"ddinsert" on_screen) 
  672.                                    (assoc ;|MSG0|;"ddinsert" ai_defaults)
  673.                                    ai_defaults
  674.                             )
  675.           )
  676.           (setq ai_defaults (cons (list ;|MSG0|;"ddinsert" on_screen) ai_defaults))
  677.         )
  678.        )
  679.     )
  680.   )
  681.  
  682.   ;; Set up error function.
  683.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  684.         old_error  *error*            ; save current error function
  685.         *error* ai_error              ; new error function
  686.   )
  687.  
  688.   (setvar "cmdecho" 0)
  689.  
  690.   (cond
  691.      (  (not (ai_notrans)))                       ; transparent not OK
  692.      (  (not (ai_acadapp)))                       ; ACADAPP.EXP xloaded?
  693.      (  (not (setq dcl_id (ai_dcl ;|MSG0|;"ddinsert"))))  ; is .DCL file loaded?
  694.  
  695.      (t (ddinsert_main))                          ; proceed!
  696.   )
  697.  
  698.   (setq *error* old_error) 
  699.   (setvar "cmdecho" old_cmd)
  700.   (princ)
  701. )
  702. ;;;----------------------------------------------------------------------------
  703. (princ "  DDINSERT cargada.")
  704. (princ)
  705.