home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CAD08N06.ZIP / LAY_CONV.LSP < prev    next >
Text File  |  1993-04-01  |  4KB  |  97 lines

  1. ;This routine reads a ".lyr" file that must be created from the drawing
  2. ;before you execute LAY_CONV by using LAY-OUT. You must edit the lines
  3. ;in the ".lyr" file to include the new layer names before the existing
  4. ;names like so:
  5. ;before edit: ARWALL 7 CONTINUOUS
  6. ;after edit: A-WALL-FULL ARWALL 7 CONTINUOUS
  7. ;
  8. ;You may change the layer color and linetype, also. Make sure that you
  9. ;do not alter the number of spaces in the line beyond one additional
  10. ;space between the new layer name and the existing layer name. LAY-CONV
  11. ;will move entities to a new layer if you wish to combine two layers
  12. ;into one new layer.
  13. ;
  14. ;LAY_CONV does not alter layer names within blocks. You must write the
  15. ;block out to a file, convert the block to the new layer name, and
  16. ;re-define the block. To delete layer names that are no longer used but
  17. ;remain in the file due to a combining of layers you must use the
  18. ;AutoCAD PURGE command or write-block all entities out to a new file.
  19.  
  20. (prompt "\nTo execute type LAY_CONV at the AutoCAD command prompt.")
  21.  
  22. (defun c:lay_conv (/ ocme ex_pt dw_nm sl_ctr ch ly_fil lin_no ly_str
  23.                    ly_clr ctr st_no sp_ctr nly_nm oly_nm ly_clr ly_lt ly_set)
  24.  (setq ocme (getvar "cmdecho"))
  25.  (setvar "cmdecho" 0)
  26.  (setq ex_pt (getvar "expert"))
  27.  (setvar "expert" 5)
  28.  (prompt "\nChecking layers... please wait.")
  29.  (command "'layer" "off" "*" "");turns off layers to speed up a redraw
  30.  (setq dw_nm (getvar "dwgname"))
  31.  (setq sl_ctr 1 
  32.        ctr 1
  33.  )
  34.  (while (/= "" (setq ch (substr dw_nm ctr 1)));parses drawing name 
  35.   (if (= ch "\\")                             ;from any path.
  36.    (setq sl_ctr ctr)
  37.   )
  38.   (setq ctr (1+ ctr))
  39.  )
  40.  (if (> sl_ctr 1)
  41.   (setq dw_nm (substr dw_nm (1+ sl_ctr) (- (strlen dw_nm) sl_ctr)))
  42.  )
  43.  (if (setq ly_fil (open (strcat dw_nm ".lyr") "r"));looks for the associated
  44.   (progn                                           ;layer data file
  45.    (setq lin_no 1)
  46.    (while (setq ly_str (read-line ly_fil))
  47.     (setq sp_ctr 0 ctr 1 st_no 0)
  48.     (while (/= "" (setq ch (substr ly_str ctr 1)))
  49.      (if (= " " ch)
  50.       (progn
  51.        (cond 
  52.         ((= st_no 0) (setq nly_nm (substr ly_str (1+ sp_ctr) 
  53.                       (- ctr (1+ sp_ctr)))))
  54.         ((= st_no 1) (setq oly_nm (substr ly_str (1+ sp_ctr)
  55.                       (- ctr (1+ sp_ctr)))))
  56.         ((= st_no 2) (setq ly_clr (substr ly_str (1+ sp_ctr)
  57.                       (- ctr (1+ sp_ctr)))))
  58.        )
  59.        (setq st_no (1+ st_no) sp_ctr ctr)
  60.       )
  61.      )
  62.      (setq ctr (1+ ctr))
  63.     )
  64.     (if (= st_no 3);makes sure that the layer file has been edited
  65.      (setq ly_lt (substr ly_str (1+ sp_ctr) (- (strlen ly_str) sp_ctr)))
  66.     )
  67.     (if (and nly_nm oly_nm ly_clr ly_lt);tests to make sure the proper
  68.      (progn                             ;data was found.
  69.       (if (not (tblsearch "layer" nly_nm));makes sure layer doesn't exist
  70.        (command "rename" "la" oly_nm nly_nm)
  71.        (progn
  72.         (setq ly_set (ssget "x" (list (cons 8 oly_nm))));finds entities
  73.         (if ly_set                                      ;on duplicate layers.
  74.          (command "chprop" ly_set "" "la" nly_nm "")
  75.         )
  76.         (setq ly_set nil)
  77.        )
  78.       )
  79.       (command "'layer" "c" ly_clr nly_nm "lt" ly_lt nly_nm "");sets color
  80.      )                                                         ;and linetype.
  81.      (prompt 
  82.       (strcat "Error found in " (strcat dw_nm ".lyr") " on line " 
  83.         (itoa lin_no) ".");notifies user of improperly edited data file.
  84.      )
  85.     )
  86.     (setq lin_no (1+ lin_no) nly_nm nil oly_nm nil ly_clr nil ly_lt nil)
  87.    )
  88.    (command "layer" "on" "*" "")
  89.    (command "regenall")
  90.   )
  91.   (prompt "\nThe proper layer data file for this drawing was not found...")
  92.  )
  93.  (setvar "cmdecho" ocme)
  94.  (setvar "expert" ex_pt)
  95.  (princ)
  96. )
  97.