;;-----------------------=={ 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 lst obl sel tab )
    (mini_start nil)
    (setq tab (if (= 1 (getvar 'cvport)) (getvar 'ctab) "MODEL"))
    (and (ssget (list (cons 410 tab)))
         (progn
            (vlax-for lay (vla-get-layouts (LM:acdoc))
                (setq obl (vla-get-name lay))
                (or (= tab (strcase obl))
                    (setq lst (cons (list obl lay) lst))
                )
            )
            (setq obl nil
                  lst (vl-sort lst '(lambda ( a b ) (< (vla-get-taborder (cadr a)) (vla-get-taborder (cadr b)))))
                  lst (mapcar '(lambda ( x ) (cadr (nth x lst)))
                              (mai_list_select "Ñ¡Ôñ¸´ÖÆÊµÌåµ½µÄÒ»¸ö»ò¶à¸ö²¼¾Ö" (mapcar 'car lst) nil T)
                      )
            )
         )
         (progn
            (vlax-for obj (setq sel (vla-get-activeselectionset (LM:acdoc)))
                (setq obl (cons obj obl))
            )
            (vla-delete sel)
            (foreach lay lst (vlax-invoke (LM:acdoc) 'copyobjects obl (vla-get-block lay)))
         )
    )
    (mai_end)
)


;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
