Jump to content

Recommended Posts

Posted

I use Alan's code shown here:

Original Code

 

;; Zoom extents in All Layouts (excluding Model)
 ;; Alan J. Thompson
 (or *Acad* (setq *Acad* (vlax-get-acad-object)))
 (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument *Acad*)))
 ((lambda (ctab)
    (foreach layout (layoutlist)
      (setvar 'ctab layout)
      (vla-put-mspace *AcadDoc* :vlax-false)
      (vla-zoomextents *Acad*)
    )
    (setvar 'ctab ctab)
  )
   (getvar 'ctab)
 )
 (princ)

 

It works perfectly and returns you to the Layout/Current Tab you started the command in each time

 

How can I get this to go to the very first tab prior to running the code? (or afterwards - either way)

 

Looking around I found this code which returns a list of tabs but I do not know how to set Tab number 1 to be the current tab

 

(vlax-for lay 
		(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
		(setq lst (cons (list (vla-get-taborder lay)(vla-get-name lay)) lst))
	)

 

Wanting to show that I'm at least "trying" I know that there is this:

 

(command "Layout" "Set" "X") ;; Solve for X

 

 

I'm sure this is much easier than I'm making it..

Posted

Is there a simple statement for going to the very first tab?
I have other routines I'm working on that need that as well...

Posted (edited)

From here. The original lisp build a list of tabs and sorted them from the 71 dxf code left to right. modified it to just look for the first tab and set it as current

Modified it to look for the tab # user defines and set it to current tab.

 

 

 

(defun TAB (x / laylst tab lay)
  (setq laylst (massoc 350 (dictsearch (namedobjdict) "acad_layout")))
  (foreach tab laylst
    (setq lay (entget tab))
    (if (eq x (cdr (assoc 71 lay))) ;made it dynamic
      (setvar 'ctab (last (massoc 1 lay)))      
    )
  )
)

(defun massoc (key alist / nlist)
  (foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
    )
  )
  (reverse nlist)
)

 

So for the first layout it would be

 

(TAB 1) ;go to first tab
(TAB 4) ;go to fourth tab

 

Edited by mhupp
Changed code to be dynamic
Posted

I have to to laugh...

If you provide a solution, they want options,

if you provide options, they want a simple solution...

 

In my case, I will always want to go to Tab 1 <only>

 

What will that code look like eliminating the option/dynamic option? 

 

This works but is it the best way?
 

(defun c:ZAL (/)
 ;; Zoom extents in All Layouts (excluding Model)
 ;; Alan J. Thompson

(defun TAB (x / laylst tab lay)
;;;; mhupp 2022.06.06 
;;;; https://www.cadtutor.net/forum/topic/75347-zoom-extents-all-layouts-2022/
  (setq laylst (massoc 350 (dictsearch (namedobjdict) "acad_layout")))
  (foreach tab laylst
    (setq lay (entget tab))
    (if (eq x (cdr (assoc 71 lay))) ;made it dynamic
      (setvar 'ctab (last (massoc 1 lay)))      
    )
  )
)
(defun massoc (key alist / nlist)
  (foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
    )
  )
  (reverse nlist)
)
(Tab 1)
 (or *Acad* (setq *Acad* (vlax-get-acad-object)))
 (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument *Acad*)))
 ((lambda (ctab)
    (foreach layout (layoutlist)
      (setvar 'ctab layout)
      (vla-put-mspace *AcadDoc* :vlax-false)
      (vla-zoomextents *Acad*)
    )
    (setvar 'ctab ctab)
  )
   (getvar 'ctab)
 )
 (princ)
)

 

Thank you!

Posted (edited)

<Deleted>

Edited by ILoveMadoka
Posted

(layoutlist) will list the layout tab names

(setvar 'ctab (nth 0 (layoutlist))) will take you to the first layout in that list, you could add this in as the first line?

 

Note that the first layout isn't necessary what you might consider to be the first layout (typically the one shown as the left hand layout tab), but will be the first layout the was created (typicaly Layout1 or whatever it is renamed to be) regardless of where in the tabs list it is shown.

Posted

Thank you again!

Posted (edited)
11 hours ago, Steven P said:

Note that the first layout isn't necessary what you might consider to be the first layout (typically the one shown as the left hand layout tab), but will be the first layout the was created (typicaly Layout1 or whatever it is renamed to be) regardless of where in the tabs list it is shown.

 

That's why I left it dynamic

 

 

11 hours ago, ILoveMadoka said:

This works but is it the best way

 

always a better way. little googling

 

(defun c:ZAL (/)
 ;; Zoom extents in All Layouts (excluding Model)
 ;; Alan J. Thompson
 (vl-load-com)
 (or *Acad* (setq *Acad* (vlax-get-acad-object)))
 (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument *Acad*)))
 ((lambda (ctab)
    (foreach layout (layoutlist)
      (setvar 'ctab layout)
      (vla-put-mspace *AcadDoc* :vlax-false)
      (vla-zoomextents *Acad*)
    )
    (setvar 'ctab ctab)
  )
   (getvar 'ctab)
 )
 (vlax-for i (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= (vla-get-taborder i) 1) (setvar 'ctab (vla-get-name i))))
 (princ)
)

 

Edited by mhupp
  • 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...