; ============================================================ ;
; COPY2LAYOUTS.LSP v1.00 (02-21-2011) /by kruuger/ ;
; ============================================================ ;
; ;
; History of changes: ;
; ------------------- ;
; 1.00 [02-21-2011] - first release ;
; ============================================================ ;
(vl-load-com)
; ============================================================ ;
; FUNCTION SYNTAX: ;
; - C2A - copy objects thru all layout tabs ;
; - C2L - copy objects thru selected layout tabs (DCL) ;
; ============================================================ ;
(defun C:C2A ()
(kr:C2L_SelectMode nil)
(princ)
)
; ============================================================ ;
(defun C:C2L ()
(kr:C2L_SelectMode T)
(princ)
)
; ============================================================ ;
(defun kr:C2L_SelectMode (Mode / SS)
(if
(and
(= (getvar 'CVPORT) 1)
(= (getvar 'TILEMODE) 0)
)
(if (> (length (layoutlist)) 1)
(progn
(prompt "\nSelect object(s) to copy thru layout tabs: ")
(if (setq SS (ssget))
(progn
(if Mode
(kr:C2L_Dialog SS)
(progn
(vla-StartUndoMark (kr:ACX_ADoc))
(kr:C2L_CopyRoutine
SS
(vl-remove
(vla-Get-ActiveLayout (kr:ACX_ADoc))
(kr:DWG_VLALayoutsList)
)
)
(vla-EndUndoMark (kr:ACX_ADoc))
)
)
)
(princ "\n>> Nothing selected. ")
)
)
(princ "\n>> No layouts to copy objects to. ")
)
(princ "\n>> This command does not work in modelspace or active viewport. ")
)
)
; ============================================================ ;
; Write C2L dialog ;
; ============================================================ ;
(defun kr:C2L_DclWrite (/ PATH FL)
(setq PATH (strcat (getenv "TEMP") "\\" "Copy2Layouts.dcl"))
(if (setq FL (open PATH "w"))
(progn
(foreach %
(list
"//===================================//"
"// MAIN_DIALOG //"
"//===================================//"
"C2L : dialog {"
" label = \"Copy2Layouts v1.00\";"
" height = 10;"
" : boxed_column {"
" label = \"Layouts:\";"
" : list_box {"
" key = \"LAYOUT\";"
" multiple_select = true;"
" }"
" : toggle {"
" key = \"ALL\";"
" label = \"Select all\";"
" mnemonic = \"a\";"
" }"
" }"
" BUTTON_OK_CANCEL;"
"}"
"//===================================//"
"// SUB_DIALOG_FUNCTION //"
"//===================================//"
"BUTTON12"
" : button {"
" width = 12;"
" horizontal_margin = none;"
" }"
"BUTTON_OK_CANCEL"
" : row {"
" : BUTTON12 {"
" label = \"Ok\";"
" mnemonic = \"O\";"
" key = \"OK\";"
" is_default = true;"
" }"
" : BUTTON12 {"
" label = \"Cancel\";"
" mnemonic = \"C\";"
" key = \"Cancel\";"
" is_cancel = true;"
" }"
" }"
)
(write-line % FL)
)
(setq FL (close FL))
T
)
nil
)
)
; ============================================================ ;
; C2L dialog ;
; ============================================================ ;
(defun kr:C2L_Dialog (Ss / DCL ACT IN POS)
(cond
( (not (kr:C2L_DclWrite))
(alert "DCL file could not be written.")
)
( (> End of C2L routine. ")
)
( (= ACT 1)
(vla-StartUndoMark (kr:ACX_ADoc))
(kr:C2L_CopyRoutine Ss
(mapcar
'(lambda (%1)
(kr:DWG_LayoutToVLA %1)
)
(mapcar
'(lambda (%)
(nth % IN)
)
(read (strcat "(" OUT ")"))
)
)
)
(vla-EndUndoMark (kr:ACX_ADoc))
)
)
)
)
)
; ============================================================ ;
; Handling of toggle/button ;
; ============================================================ ;
(defun kr:C2L_ToggleAll (Val Lst Pos)
(if (zerop (atoi Val))
(if Pos
(progn
(foreach % (list "" Pos)
(set_tile "LAYOUT" %)
)
(mode_tile "OK" 0)
)
(progn
(set_tile "LAYOUT" "")
(mode_tile "OK" 1)
)
)
(progn
(kr:DLG_ListBoxSelectAll "LAYOUT" Lst)
(mode_tile "OK" 0)
)
)
)
; ============================================================ ;
; Copy tabs main routine ;
; ============================================================ ;
(defun kr:C2L_CopyRoutine (Ss In / LL)
(mapcar
'(lambda (%)
(vlax-Invoke
(kr:ACX_ADoc)
'CopyObjects
(kr:SSX_SS->VLA Ss)
(vla-Get-Block %)
nil
)
)
(setq LL In)
)
(princ
(strcat
(itoa (sslength Ss))
" object(s) was copied to "
(itoa (length LL))
" layout(s). "
)
)
)

; ************************************************************ ;
; LIBRARY FUNCTION ;
; ************************************************************ ;

; ============================================================ ;
; Retrieves pointers to the Active Document ;
; ============================================================ ;
(defun kr:ACX_ADoc ()
(or
*kr-ADoc
(setq *kr-ADoc
(vla-Get-ActiveDocument
(vlax-Get-Acad-Object)
)
)
)
*kr-ADoc
)
; =============================================================;
; Sets a dialog "popup_list" or "list_box" tile to a list ;
; Key [STR] - key name of tile ;
; Lst [STR] - list to set in tile ;
; Pos [STR] - a list of items selected ;
; =============================================================;
(defun kr:DLG_SetTileList (Key Lst Pos)
(start_list Key)
(mapcar 'add_list Lst)
(end_list)
(if
(and
Pos
(= (type Pos) 'STR)
)
(set_tile Key Pos)
)
)
; ============================================================ ;
; Select all position on list_box control ;
; ============================================================ ;
(defun kr:DLG_ListBoxSelectAll (Key Lst / POS)
(setq POS 0)
(repeat (length Lst)
(set_tile Key (itoa POS))
(setq POS (1+ POS))
)
)

; ============================================================ ;
; List of VLA layouts objects ;
; ============================================================ ;
(defun kr:DWG_VLALayoutsList ()
(cdr
(vl-Sort
(
(lambda (/ L#)
(vlax-For %
(vla-Get-Layouts (kr:ACX_ADoc))
(setq L# (cons % L#))
)
L#
)
)
(function
(lambda (e1 e2)
(VLA (Sel / N L#)
(repeat (setq N (sslength Sel))
(setq N (1- N)
L# (cons (vlax-ename->vla-object (ssname Sel N)) L#)
)
)
)
; ============================================================ ;
; Start undo mark ;
; ============================================================ ;
(defun kr:SYS_StartUndo ()
(vla-StartUndoMark (kr:ACX_ADoc))
)
; ============================================================ ;
; End undo mark ;
; ============================================================ ;
(defun kr:SYS_EndUndo ()
(vla-EndUndoMark (kr:ACX_ADoc))
)

(princ "\n** Loaded COPY2LAYOUTS.LSP (02-2011) /by kruuger/. Type C2A, C2L to invoke **")
(princ)(c:c2l)

Advertisements