Charpzy Posted Wednesday at 10:46 AM Posted Wednesday at 10:46 AM Hi, I’ve made a script that finds all plan borders (polygons/boxes) on a specific layer, grabs the text inside each one, then creates new layouts using the bounding box (LL & UR) and names them accordingly. It works fine on small files almost instantly creating the tabs/layouts, but as the file size grows, it slows down a lot — specifically around when creating layouts and switching tabs. Would switching from a Command to VLA help speed this up? id just like to optimise this as much as i possibly could Here’s the part of the script that handles layout creation: ;; Process each plan (foreach plan border-list (setq layout-name (car plan) LL (cadr plan) UR (caddr plan) layout-orientation (last plan)) ;; Create layout - can we change this to VLA? speed up the copy function? (command ".layout" "copy" layout-orientation layout-name) ;; Set active layout (setq layname (vla-Item layouts (1- (vla-get-Count layouts)))) (vla-put-ActiveLayout doc layname) ;; Set viewport (vla-put-Mspace doc :vlax-true) (vla-ZoomWindow app LL UR) (vla-put-Mspace doc :vlax-false) (setq done (1+ done)) (princ (strcat "\n" (itoa done) "/" (itoa total))) ) Quote
SLW210 Posted Wednesday at 12:18 PM Posted Wednesday at 12:18 PM Maybe this thread will help... How to copy a layout using vla object? - AutoLISP, Visual LISP & DCL - AutoCAD Forums Quote
BIGAL Posted Thursday at 01:22 AM Posted Thursday at 01:22 AM When you say slows down, I have something similar and have made 40+ layouts in one go and just watch the screen flash, if you compare the time to make 40+ layouts its so much faster. Maybe ;; Set active layout (setq layname (vla-Item layouts (1- (vla-get-Count layouts)))) (vla-put-ActiveLayout doc layname) (setvar 'ctab layname) My code looks at what title block to use and what scale the rectangs are to represent, the rectangs can be rotated so viewport is twisted. yes have a version that allows the rectangs to be different tittle blocks. There is other make layouts lisp out there maybe have a look at what method used to create the layouts. Quote
mhupp Posted Thursday at 03:34 AM Posted Thursday at 03:34 AM (edited) You can tell AutoCAD to temporarily suspend view updates to speed up AutoLISP operations like creating layouts Never mind, The REGENMODE system variable is no longer needed and is not functional. needed mindpoint of UR LL and the length and width of the rectangle to create the view port. (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) ;while setting up drawing just also add a undo mark ... (acet-ui-progress-init "Creating Layouts..." total) (foreach plan border-list (setq layout-name (car plan) LL (cadr plan) UR (caddr plan) MPT (mapcar '/ (mapcar '+ LL UR) '(2 2 2)) ;midmpoint L&W (mapcar '- UR LL) ;returns a point that is the length and width (X,Y) of the rectangle layout-orientation (last plan) ;don't know what this is angle? ) (setq layouts (vla-get-Layouts Drawing)) (setq newLayout (vla-Add layouts layout-name)) ;could error if layout-name is existing? (vla-Activate Drawing newLayout) ;; Activate the new layout (setq ps (vla-get-PaperSpace Drawing)) ;switch to PaperSpace on new layout ;; Create a viewport at MPT, Length, Width (setq vp (vla-AddPViewport ps (vlax-3d-point MPT) (cadr L&W) (car L&W))) (setq i (1+ i)) ;I like i for counting (acet-ui-progress-safe i) ;instead of spamming command prompt, output to window or status bar ;(princ (strcat "\n" (itoa done) "/" (itoa total))) ) (acet-ui-progress-done) ... (vla-endundomark Drawing) (vla-Regen Drawing acAllViewports) or zoom to rectangle and copy these system variables (setq vc (getvar 'viewctr)) (setq sz (getvar 'viewsize)) (vla-zoomcenter Drawing VC SZ) Edited yesterday at 02:54 AM by mhupp Quote
hosneyalaa Posted Thursday at 04:49 AM Posted Thursday at 04:49 AM 17 hours ago, Charpzy said: ;; Create layout - can we change this to VLA? speed up the copy function? (command ".layout" "copy" layout-orientation layout-name) TRY (vl-cmdf "._layout" "c" layout-orientation layout-name) Quote
Danielm103 Posted Thursday at 08:53 AM Posted Thursday at 08:53 AM This was recently discussed in PyRx, How to batch create layouts? https://github.com/CEXT-Dan/PyRx/discussions/368 Each time you create a layout, AutoCAD will cache the graphics of the viewports, consuming large amounts of memory and slowing the process, you can try to turn off the cache as explained here https://github.com/CEXT-Dan/PyRx/discussions/368#discussioncomment-13604115 But… it is what it is, layouts are a resource hog 1 Quote
Saxlle Posted Thursday at 09:20 AM Posted Thursday at 09:20 AM (edited) Thank you @Danielm103 for the information, next time, I will try to play with this (because I'm also occuring with this problem, not always, but it happens). Also, there is LAYOUTREGENCTL (System Variable), same thing which can be found in Option -> System. Edited Thursday at 09:23 AM by Saxlle 1 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.