aridzv Posted May 13 Posted May 13 Hi. I want to copy the current layout to a new layout by the name "A-44". I'm trying to replace this: (command "._layout" "_copy" "" "A-44") with this: (defun c:test2 ( / curtab doc laylst) (setq curtab (getvar 'ctab)) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq laylst (vla-get-Layouts doc)) (vlax-for lay laylst (if (= (vla-get-name lay) curtab) (vlax-invoke doc 'copyobjects "A-44" (vla-get-block lay)) ;(princ (vla-get-name lay)) );if )vlax-for );defun But ran into a brick wall... I would appreciate any help... thanks, aridzv. Quote
hosneyalaa Posted May 13 Posted May 13 41 minutes ago, aridzv said: I'm trying to replace this: (command "._layout" "_copy" "" "A-44") TRY (vl-cmdf "._layout" "c" curtab "A-44") 1 Quote
GLAVCVS Posted May 13 Posted May 13 (edited) Try (defun c:test2 ( / curtab doc layI laylst dameObjs) (defun dameObjs (lay / lcj) (vlax-for o (vla-get-block lay) (setq lcj (cons o lcj)) ) ) (setq curtab (getvar 'ctab)) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq laylst (vla-get-Layouts doc)) (setq layI (vla-item laylst "A-44")) (vlax-for lay laylst (if (= (vla-get-name lay) curtab) (vla-copyObjects doc (vlax-make-variant (vlax-safeArray-Fill (vlax-make-safeArray 9 (cons 0 (1- (length (setq lcj (dameObjs layI)))))) lcj)) (vla-get-block lay)) );if ) ) Edited May 13 by GLAVCVS Quote
Steven P Posted May 13 Posted May 13 Could just entmake the new layer: Note for this is that if the layer has for example transparencies and others set you might need to acount for them too, but this does a standard layer. (DEFUN c:Copylayer ( / ) (setq MyLayer (getstring "Enter the layer to copy " T )) (if (TBLSEARCH "LAYER" MyLayer) (progn (setq LayEnt (TBLSEARCH "LAYER" MyLayer)) (setq NewName (getstring "Enter the new layer Name " T )) (setq NewLayer (entmakex (list (cons 0 (cdr (assoc 0 LayEnt))) (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 NewName) (cons 70 (cdr (assoc 70 LayEnt))) (cons 62 (cdr (assoc 62 LayEnt))) (cons 6 (cdr (assoc 6 LayEnt))) ) ) ) ; end list, end entmakex, end setq ) ; end progn (progn (princ "\nTry again, layer doesn't exist") ) ) ; end if (princ) ) Quote
aridzv Posted May 13 Author Posted May 13 3 hours ago, GLAVCVS said: Try (defun c:test2 ( / curtab doc layI laylst dameObjs) (defun dameObjs (lay / lcj) (vlax-for o (vla-get-block lay) (setq lcj (cons o lcj)) ) ) (setq curtab (getvar 'ctab)) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq laylst (vla-get-Layouts doc)) (setq layI (vla-item laylst "A-44")) (vlax-for lay laylst (if (= (vla-get-name lay) curtab) (vla-copyObjects doc (vlax-make-variant (vlax-safeArray-Fill (vlax-make-safeArray 9 (cons 0 (1- (length (setq lcj (dameObjs layI)))))) lcj)) (vla-get-block lay)) );if ) ) not working... thanks anyway. aridzv. Quote
Steven P Posted May 13 Posted May 13 (edited) 1 hour ago, aridzv said: @Steven P thanks, but I need to copy layout.... Whoops, that's me not reading your question properly! (though of course, you can use entmake method to copy a layout it is a bit of a pain to do - assuming you also want anything on that layout also copied) Edited May 13 by Steven P 1 Quote
GLAVCVS Posted May 13 Posted May 13 For me, it worked. If you attached a drawing, it would be easier to see what the problem is. Quote
aridzv Posted May 13 Author Posted May 13 (edited) 56 minutes ago, GLAVCVS said: For me, it worked. If you attached a drawing, it would be easier to see what the problem is. thanks. here is a sample drawing. for the example, lets try to copy "A-4" layout and give it other name, say "A-44". thanks again!! aridzv. test.dwg Edited May 13 by aridzv Quote
Lee Mac Posted May 13 Posted May 13 Review lines 1076-1112 of my TabSort program for an example of how to accomplish this using COM; though, this is one of those scenarios where a simple command call will likely perform faster, given the number of operations involved to copy the layout - such operations can be performed by the C++ implementation of the command rather than individually interpreted through evaluation of each LISP expression. 1 Quote
aridzv Posted May 14 Author Posted May 14 @Lee Mac thanks - i'll look on the link you shared. the real slowdown in my lisp (it's a long one and custom made for my work environment so i didn't shared it here), is actualy changing the current layout tab: (setvar 'ctab lytname) especially in 3D drawings with complex objects, where it is very noticeable, and I haven't found a solution for it... thanks, aridzv. Quote
SLW210 Posted May 14 Posted May 14 Why do you need to use vla-object? Maybe ... Solved: rename/copy/switch to next layout tab lisp help - Autodesk Community Quote
aridzv Posted May 14 Author Posted May 14 (edited) 59 minutes ago, SLW210 said: Why do you need to use vla-object? generally speaking, it is an issue of trying to use the fastest way, wich means not using "command" if possible and instead using entmake\entmod or vla. about changing the current layout tab and the link you shared: 1. @Tharwat wrote here that @ronjonp do this stuff.... 2. the delay of moving between layouts is unfortunately a software issue, not command related... there are articles about this issue both in autocad and bricscad. no mather what you do, eventually you will need to use (setvar 'ctab....) and that will cause the delay. aridzv. Edited May 14 by aridzv Quote
SLW210 Posted May 14 Posted May 14 Just curious, you posted a pretty much empty sample drawing, I have some different ones you can try. These worked on your drawing with AutoCAD 2024. These add a suffix... ;;; Copy layout and add suffix (focus on new layout) ;;; ;;; https://www.cadtutor.net/forum/topic/97834-how-to-copy-a-layout-using-vla-object/#findComment-670382 ;;; ;;; SLW210 (a.k.a. Steve Wilson ;;; (defun c:CLAS_VLA ( / acadObj doc layouts oldLayout newSuffix newLayoutName newLayout oldLayoutObj psOld psNew ss) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq oldLayout (getvar "CTAB")) (if (wcmatch oldLayout "Model") (princ "\nCannot copy the Model tab.") (progn (setq newSuffix (getstring "\nEnter text to add to layout name (e.g., '_rev1'): ")) (setq newLayoutName (strcat oldLayout newSuffix)) ;; Create and copy layout settings (setq newLayout (vla-Add layouts newLayoutName)) (setq oldLayoutObj (vla-Item layouts oldLayout)) (vla-CopyFrom newLayout oldLayoutObj) ;; Get block records for old and new layout (paper space) (setq psOld (vla-get-Block oldLayoutObj)) (setq psNew (vla-get-Block newLayout)) ;; Copy entities from old layout to new layout (vlax-for ent psOld (vla-CopyObjects doc (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list ent))) psNew ) ) ;; Set the new layout as active (vla-put-ActiveLayout doc newLayout) (princ (strcat "\nLayout copied and renamed to: " newLayoutName)) ) ) (princ) ) ;;; Copy layout and add suffix (focus remains on old layout) ;;; ;;; https://www.cadtutor.net/forum/topic/97834-how-to-copy-a-layout-using-vla-object/#findComment-670382 ;;; ;;; SLW210 (a.k.a. Steve Wilson ;;; (defun c:CRL_VLA_1 ( / acadObj doc layouts oldLayout newSuffix newLayoutName newLayout oldLayoutObj psOld psNew ss) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq oldLayout (getvar "CTAB")) (if (wcmatch oldLayout "Model") (princ "\nCannot copy the Model tab.") (progn (setq newSuffix (getstring "\nEnter text to add to layout name (e.g., '_rev1'): ")) (setq newLayoutName (strcat oldLayout newSuffix)) ;; Create and copy layout settings (setq newLayout (vla-Add layouts newLayoutName)) (setq oldLayoutObj (vla-Item layouts oldLayout)) (vla-CopyFrom newLayout oldLayoutObj) ;; Get block records for old and new layout (paper space) (setq psOld (vla-get-Block oldLayoutObj)) (setq psNew (vla-get-Block newLayout)) ;; Copy entities from old layout to new layout (vlax-for ent psOld (vla-CopyObjects doc (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list ent))) psNew ) ) (princ (strcat "\nLayout copied and renamed to: " newLayoutName)) ) ) (princ) ) 1 Quote
SLW210 Posted May 14 Posted May 14 Continued... These rename... ;;; Copy layout and rename (focus on new layout) ;;; ;;; https://www.cadtutor.net/forum/topic/97834-how-to-copy-a-layout-using-vla-object/#findComment-670382 ;;; ;;; SLW210 (a.k.a. Steve Wilson ;;; (defun c:CRL_VLA ( / acadObj doc layouts oldLayout newLayoutName newLayout oldLayoutObj psOld psNew ss) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq oldLayout (getvar "CTAB")) (if (wcmatch oldLayout "Model") (princ "\nCannot copy the Model tab.") (progn (setq newLayoutName (getstring "\nEnter the full name for the new layout (e.g., 'A-44_rev1'): ")) ;; Create and copy layout settings (setq newLayout (vla-Add layouts newLayoutName)) (setq oldLayoutObj (vla-Item layouts oldLayout)) (vla-CopyFrom newLayout oldLayoutObj) ;; Get block records for old and new layout (setq psOld (vla-get-Block oldLayoutObj)) (setq psNew (vla-get-Block newLayout)) ;; Copy entities from old layout to new layout (vlax-for ent psOld (vla-CopyObjects doc (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list ent))) psNew ) ) ;; Set the new layout as active (vla-put-ActiveLayout doc newLayout) (princ (strcat "\nLayout copied and renamed to: " newLayoutName)) ) ) (princ) ) ;;; Copy layout and rename (focus remains on old layout) ;;; ;;; https://www.cadtutor.net/forum/topic/97834-how-to-copy-a-layout-using-vla-object/#findComment-670382 ;;; ;;; SLW210 (a.k.a. Steve Wilson ;;; (defun c:CRL_VLA_1 ( / acadObj doc layouts oldLayout newLayoutName newLayout oldLayoutObj psOld psNew ss) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq oldLayout (getvar "CTAB")) (if (wcmatch oldLayout "Model") (princ "\nCannot copy the Model tab.") (progn (setq newLayoutName (getstring "\nEnter the full name for the new layout (e.g., 'A-44_rev1'): ")) ;; Create and copy layout settings (setq newLayout (vla-Add layouts newLayoutName)) (setq oldLayoutObj (vla-Item layouts oldLayout)) (vla-CopyFrom newLayout oldLayoutObj) ;; Get block records for old and new layout (paper space) (setq psOld (vla-get-Block oldLayoutObj)) (setq psNew (vla-get-Block newLayout)) ;; Copy entities from old layout to new layout (vlax-for ent psOld (vla-CopyObjects doc (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list ent))) psNew ) ) (princ (strcat "\nLayout copied and renamed to: " newLayoutName)) ) ) (princ) ) 1 Quote
Danielm103 Posted May 14 Posted May 14 On 5/13/2025 at 8:41 PM, aridzv said: Hi. I want to copy the current layout to a new layout by the name "A-44". Aren't you setup with Python? use the LayoutManager from pyrx import Rx, Ge, Gi, Db, Ap, Ed, command @command def doit(): db = Db.curDb() fromTab = Ed.Core.getVar('ctab') ps, toTab = Ed.Editor.getString(1, "Enter a tabname: ") if ps == Ed.PromptStatus.eOk: lm = Db.LayoutManager() lm.copyLayout(fromTab, toTab, db) 1 Quote
aridzv Posted May 14 Author Posted May 14 @Danielm103 Hi!! Despite that post where you helped me with that table with images, I'm not even close to being able to implement the 'ctab conversion in Python. Not to mention that the 'ctab section is just a small part of a larger lisp, which I certainly can't rewrite in Python... thanks, aridzv. 1 Quote
Danielm103 Posted May 14 Posted May 14 Okay, sorry about that. If you get stuck, here’s a lisp callable function (copyLayout "A-4" "A-44") from pyrx import Rx, Ge, Gi, Db, Ap, Ed import traceback @Ap.LispFunction() def copyLayout(args): try: if len(args) != 2: return None t1, fromLayout = args[0] t2, toLayout = args[1] db = Db.curDb() lm = Db.LayoutManager() lm.copyLayout(fromLayout, toLayout, db) return True except Exception as err: traceback.print_exception(err) return None 1 Quote
BIGAL Posted May 15 Posted May 15 Ok not copy but goto, as name implies when you have lots of layouts example a dwg with 88 layouts so Goto 1 look up index then goto 23. goto 99 goes to last layout. A Goto is not included in CAD but is in a lot of other software, so wrote one years ago. Goto-layout.lsp 1 Quote
aridzv Posted May 15 Author Posted May 15 5 hours ago, BIGAL said: Ok not copy but goto, as name implies when you have lots of layouts example a dwg with 88 layouts so Goto 1 look up index then goto 23. goto 99 goes to last layout. A Goto is not included in CAD but is in a lot of other software, so wrote one years ago. Goto-layout.lsp 829 B · 31 downloads no dcl... so I changed this: (setq num (atoi (nth 0 (AH:getvalsm (list "Go To A Layout" "Enter layout number" 5 4 "1"))))) to this: (setq num (getint "Enter layout number:")) nice one. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.