Jump to content

Layout Tab Selection


magic_man1

Recommended Posts

It seems that I am .lsp illiterate, but hey, I'm trying to learn.

 

Hopefully you can help me. I am looking for a piece of .lsp code that will allow me to go between layout tabs one at a time. The catch is that I need this to function like the keyboard stroke: Ctrl+Page Up or Ctrl+Page Down, where it simply jumps up/down one layout at a time, without needing to know the layout name.

 

Extra credit: To have this function start with the first layout tab and progresses through to the last layout tab (say, 20 layout tabs)

 

Does anyone know if this is possible?

 

I will be performing other tasks for each "current" layout as they are active, so I imagine that I would simply repeat a piece of code after I inject my code for each layout. Again... trying to teach myself how to do this.

 

Thanks in advance for your help.

Link to comment
Share on other sites

The layout tabs are a table so you can get a list of them and I am pretty sure you can change a variable to set current tab value.

 

"CTAB" yep that works.

 

From help

Finds the next item in a symbol table

(tblnext table-name [rewind])

When tblnext is used repeatedly, it normally returns the next entry in the specified table each time. The tblsearch function can set the next entry to be retrieved. If the rewind argument is present and is not nil, the symbol tableis rewound and the first entry in it is retrieved.

Arguments

table-name A string that identifies a symbol table. Valid table-name values are "LAYER", "LTYPE", "VIEW", "STYLE", "BLOCK", "UCS", "APPID", "DIMSTYLE", and "VPORT". The argument is not case sensitive.

 

Search here for layout table should be some code available

Link to comment
Share on other sites

Step through the (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) and make a list of all layouts, sorted based on vla-get-taborder.

From there, you can easily step through the layout list and either jump to next or previous.

 

Just use (setvar 'ctab ) to set your current layout tab.

 

I found this to be fun. Here's a little inspiration:

tj.gif

 

It doesn't show it in the video, but it will jump to the first if you go past the last and vise-versa.

Link to comment
Share on other sites

Yeah, true

 

(defun Test1 nil
 (
   (lambda ( LayoutCollection )
     (vl-sort (cons "Model" (layoutlist))
      '(lambda ( layout1 layout2 )
         (< (vla-get-TabOrder (vla-item LayoutCollection layout1))
            (vla-get-TabOrder (vla-item LayoutCollection layout2))
         )
       )
     )
   )
   (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
 )
)

(defun Test2 nil
 (
   (lambda ( LayoutCollection / l )
     (mapcar 'vla-get-Name
       (vl-sort (vlax-for Layout LayoutCollection (setq l (cons Layout l)))
        '(lambda ( layout1 layout2 )
           (< (vla-get-TabOrder layout1)
              (vla-get-TabOrder layout2)
           )
         )
       )
     )
   )
   (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
 )
)

 

Elapsed milliseconds / relative speed for 4096 iteration(s):

   (TEST2).....1966 / 1.16 <fastest>
   (TEST1).....2277 / 1.00 <slowest>

Link to comment
Share on other sites

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