(defun c:export_dwg_by_layer ( / pa la-lst ss fn) 
  (defun tablelist (s / d r) 
    (while 
      (setq d (tblnext s (null d))) 
       (setq r (cons (cdr (assoc 2 d)) r)) 
    ) 
  ) 
  (setq pa (getfiled "ÎÄ¼þÊä³öµ½" "" "dwg" 1)) 
  (setq pa (substr pa 1 (- (strlen pa) 4))) 
  (setq la-lst (tablelist "layer")) 
  (foreach n la-lst 
    (setq ss (ssget "x" (list (cons 8 n)))) 
    (if    ss 
      (if (findfile (setq fn (strcat pa "_" n ".dwg"))) 
    (command "-wblock" fn "y" "" "0,0,0" ss "" "oops") 
    (command "-wblock" fn "" "0,0,0" ss "" "oops") 
      ) 
    ) 
  ) 
)
