buntobaggins Posted Wednesday at 10:10 PM Posted Wednesday at 10:10 PM I am currently writing a program that will take layouts defined in a template file and copy them over to the current drawing. But running this program will cause the the file to break. The new layouts will not show up and if you attempt to switch to a different layout AutoCad will crash. If you try to open the file up again AutoCad will say its corrupted and will repair the file which seems to fix the problem. (defun c:copyLayouts () (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq impdwg (getfiled "Select Master Template" "" "dwt" 16)) (setq impdoc (vla-getinterfaceobject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'acadver)))) );vla-getinterfaceobject );setq (vl-catch-all-apply 'vla-open (list impdoc impdwg)) (setq layoat (vlax-get-property impdoc 'layouts)) (setq safeLayout (vlax-make-safearray vlax-vbObject (cons 0 (- (vla-get-count layoat) 1)))) (setq i 0) (repeat (vla-get-count layoat) (vlax-safearray-put-element safeLayout i (vla-item layoat i)) (setq i (1+ i)) );repeat (vla-CopyObjects impdoc safeLayout (vlax-get-property doc 'layouts)) (princ "\n\ncopy done\n\n") (princ) );defun This only seems to be a problem with layouts. Using the same code for say a UCS works just fine. This is probably just some stupid mistake but I have been stuck on this for a while now so any help would be appreciated. Quote
mhupp Posted Thursday at 07:27 PM Posted Thursday at 07:27 PM https://www.lee-mac.com/steal.html (Steal "C:\\My Folder\\MyDrawing.dwg" '(("Layouts" ("Page1" "Page2")))) 1 Quote
buntobaggins Posted Thursday at 08:54 PM Author Posted Thursday at 08:54 PM I am aware of the Steal program but for this project I would like to write my own implementation. Quote
BIGAL Posted Thursday at 10:40 PM Posted Thursday at 10:40 PM Why not just use "Layout T" Template it asks for the dwg and which layout i have always used it and no problems. Can run as a (command 1 Quote
SLW210 Posted yesterday at 10:42 AM Posted yesterday at 10:42 AM What are you trying to accomplish with this code? First and foremost vla-CopyObjects doesn't support Layouts in the manner you are attempting, AFAIK. You need to use -LAYOUT command or pretty much need to use LeeMac's Steal or at least determine the method he uses for Layouts, which if I am looking at it correctly uses the Block Table record maybe more as I quickly glanced at it. 2 Quote
ronjonp Posted 15 hours ago Posted 15 hours ago You can also use Design Center ( DC ) to copy layouts amongst other things between drawings. Quote
BIGAL Posted 11 hours ago Posted 11 hours ago Back to your code, using OBDX you get the layout list like this. ; example code by AlanH June 2026 (setq fname (getfiled "Select dwt File" "D:\\alan" "dwt" 16)) (setq impdoc (vla-getinterfaceobject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'acadver)))) ) ) (vl-catch-all-apply 'vla-open (list impdoc impdwg)) (setq layout (vlax-get-property impdoc 'layouts)) (setq lst '()) (vlax-for lname layout (setq lst (cons (vlax-get lname 'name) lst)) ) (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq ans (ah:butts but "V" (cons "Please choose" lst))) (command "layout" "T" lname ans) You can then feed that lst to say a dcl and choose, this is using a library function that returns the layout name, save multi radio buttons in a support path or edit the (load to full path where saved. It will work for up to about 20 layout names, a screen limitation. Give it a try let me know how it works, Multi radio buttons.lsp 1 Quote
Tharwat Posted 1 hour ago Posted 1 hour ago Search in my website for the program: Import Layouts. https://AutolispPrograms.wordpress.com 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.