;;-----------------------=={ Copy to Layouts }==------------------------;;
;;                                                                      ;;
;;  This program enables a user to quickly copy a selection of objects  ;;
;;  to all or selected layouts in a drawing.                            ;;
;;                                                                      ;;
;;  Upon calling the program with 'C2L' at the command line, the user   ;;
;;  is prompted to make a selection of objects in the active layout to  ;;
;;  copy. Following selection, the user is prompted, via a dialog       ;;
;;  interface, to choose one or more layouts to which the objects will  ;;
;;  be copied.                                                          ;;
;;                                                                      ;;
;;  If the program is called with 'C2AL' at the command line, every     ;;
;;  object in the selection is automatically copied to all layouts      ;;
;;  in the drawing, without the use of the dialog interface.            ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright ?2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    10-02-2011                                      ;;
;;                                                                      ;;
;;  First Release.                                                      ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    08-07-2013                                      ;;
;;                                                                      ;;
;;  Entire program rewritten.                                           ;;
;;----------------------------------------------------------------------;;
;;选择要复制到布局的实体[lm_c2l]
;; Copy to selected layouts
(defun c:lm_c2layouts ( / old_cmd doc lst obl sel tab obj lay )
    (mini_start nil)
    (mai_last_com "lm_c2layouts")
	(setq doc (vlax-get (vlax-get-acad-object) 'activedocument))
    (setq tab (if (= 1 (getvar 'cvport)) (getvar 'ctab) "MODEL"))
    (and (ssget (list (cons 410 tab)))
         (progn
            (vlax-for lay (vlax-get doc 'layouts)
                (setq obl (vlax-get lay 'name))
                (or (= tab (strcase obl))
                    (setq lst (cons (list (vlax-get lay 'taborder) obl lay) lst))
                )
            )
            (setq obl nil
                  lst (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
                  lst (mapcar 'cdr lst)
                  lst (mapcar '(lambda ( x ) (cadr (nth x lst)))
                              (mai_list_select "选择复制实体到的一个或多个布局" (mapcar 'car lst) nil T)
                      )
            )
         )
         (progn
		    (setq sel (vlax-get doc 'activeselectionset))
            (vlax-for obj sel
                (setq obl (cons obj obl))
            )
            (vla-delete sel)
            (foreach lay lst (vlax-invoke doc 'copyobjects obl (vlax-get lay 'block)))
         )
    )
    (mai_end)
)
