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


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

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