Jump to content

Help Copying Layouts with VLA Instead of Command


Recommended Posts

Posted

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)))
  )

 

Posted

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.

Multiradio2col34.png.e8f8746b7256073461193bead0dea7a0.png

 

There is other make layouts lisp out there maybe have a look at what method used to create the layouts.

Posted (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 by mhupp
Posted
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)

 

Posted

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

 

  • Like 1
Posted (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 by Saxlle
  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...