Author Topic: Layout tab order  (Read 10368 times)

0 Members and 1 Guest are viewing this topic.

SPDCad

  • Bull Frog
  • Posts: 453
Layout tab order
« on: March 02, 2005, 03:17:36 PM »
How does one get the layout tab order displayed on the screen.
When I use (layoutlist) it gives me the layout tabs names in alphabetic order, which may not be the ordr that is displayed on screen.
Any ideas on how to get what is actual order that is displayed on screen is a list?

Any help would be appreciated. I will continue to look into the problem myself.

 :wink:
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

whdjr

  • Guest
Layout tab order
« Reply #1 on: March 02, 2005, 03:40:25 PM »
If you want to learn how to do it then research the taborder (dxf code 71).
I also have some code I can give you if you don't want to learn.
You know the whole teach a person to fish thing.... :)

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Layout tab order
« Reply #2 on: March 02, 2005, 04:19:47 PM »
And there's also the TabOrder ActiveX property.....

whdjr

  • Guest
Layout tab order
« Reply #3 on: March 02, 2005, 04:22:30 PM »
On second thought I couldn't get one to work through dxf code.  The one I already have uses Visual Lisp.

SPDCad

  • Bull Frog
  • Posts: 453
Layout tab order
« Reply #4 on: March 02, 2005, 04:41:57 PM »
I am writing my lisp with VLisp, and alot of it has been done with ActiveX coding. I was just looking for a point in the right direction. Where one would find a list or how to build a list that is based apon the tab order displayed on the screen. I have been using the (layoutlist) command to retrieve the layout names, but appeariantly the list is not in the same order that is on the screen.
Like I meantioned before, I am still reseaching/learning and experimenting the subject.  So any example would be helpful.  :)

I agree with you whdjr.  I am not looking for the fish, but to learn how to catch the fish.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

whdjr

  • Guest
Layout tab order
« Reply #5 on: March 02, 2005, 04:53:44 PM »
Using vLisp obtain the layouts collection:
Code: [Select]
(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
Then you sort the list based on the 'taborder' property.

Comprende...?

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Layout tab order
« Reply #6 on: March 02, 2005, 04:57:45 PM »
See if this kick starts you.... :D
Code: [Select]

(vlax-for layout (vla-get-layouts *doc*)
  (princ (strcat "\n" (vla-get-name layout) " - " (itoa (vla-get-taborder layout))))
  )

whdjr

  • Guest
Layout tab order
« Reply #7 on: March 02, 2005, 05:23:19 PM »
ok...gotta go in a minute so here is what I use in our office mnl file:

Code: [Select]
(vl-load-com)

(defun *layouts* () (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))

(defun *layout_list* (/ lst)
  (vlax-map-collection
    (*layouts*)
    '(lambda (x) (setq lst (cons x lst)))
  )
  (cdr
    (*sort* lst 'vla-get-taborder)
  )
)

(defun *sort* (lst func)
  (vl-sort lst
  '(lambda (e1 e2)
     (< ((eval func) e1) ((eval func) e2))
   )
  )
)


Hope this helps and not confuses you.

***edited***3/2/05---5:32pm

SPDCad

  • Bull Frog
  • Posts: 453
Layout tab order
« Reply #8 on: March 02, 2005, 09:23:28 PM »
Stupid me, I had written this code a few months back to get the layout tabs out of a drawing. Then I saw the (layoutlist) command in someone else’s code posted here and I scrapped my code for it (always trying to find ways to make my code smaller).  
Unfortunately I never finished the lisp I was working on at the time, so I missed this code.  Any how this is what I had coded at the time.

Code: [Select]
(Defun GetTabs ()
   (vl-load-com)
   (setq DWG (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
         CNT (vla-get-count DWG)
   );    
  (while (< 0 (setq CNT (1- CNT)))
     (setq TAB (vla-item DWG CNT)
           TYP (strcase (vla-get-name TAB))
     );setq
     (if (not (eq TYP "MODEL"))
         (if (= LST Nil)
             (setq LST (list TAB));
             (setq LST (append LST (list TAB));
         );
     );if
  );while
  (setq RTN LST);
);  


I am still not sure this code works, (don't have CAD at home to tester out), I will have to check tomorrow at work. Hopefully it’s a go.

Thanks to all you guys for the help. I will look at what you have coded and maybe I can improve on what I have.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

whdjr

  • Guest
Layout tab order
« Reply #9 on: March 03, 2005, 09:11:04 AM »
Here are just a few things I noticed about the code you provided.  The best thing is it works.  I included some other comments in the code for you to look at:

Code: [Select]
(Defun GetTabs (/ dwg cnt tab typ lst); rtn) not needed
 ;Always localize your variables unless
 ;intentionally using a global variable
  (vl-load-com)
  (setq DWG (vla-get-layouts
     (vla-get-activedocument (vlax-get-acad-object))
   )
CNT (vla-get-count DWG)
  )
  (while (<= 0 (setq CNT (1- CNT)))
 ;Changed the < to <= because 0 is a valid item.
    (setq TAB (vla-item DWG CNT)
 TYP (strcase (vla-get-name TAB))
    )
    (if (not (eq TYP "MODEL"))
 ;If you use cons instead of append to create your list
 ;then you won't need to test LST first.
 ;(if (= LST Nil)
 ;(setq LST (list TAB))
 ;(setq LST (append LST (list TAB)))
 ;)
      (setq LST (cons TAB LST))
    )
  )
 ;If this is returning a list to another function you don't
 ;need to set this another variable just return the one
 ;already established.
 ;(setq RTN LST)
  LST
)



Another way to do the same thing using vlax-for instead of while is:
(vlax-for is the same as foreach except used on a collection)
Code: [Select]
(Defun GetTabs2 (/ dwg typ lst)
  (vl-load-com)
  (setq dwg (vla-get-layouts
     (vla-get-activedocument
(vlax-get-acad-object))
   )
  )
  (vlax-for lay dwg
    (setq typ (strcase (vla-get-name lay)))
    (if (not (eq typ "MODEL"))
      (setq lst (cons lay lst))
    )
  )
  lst
)


But these methods do not put the layouttabs in order they just return a list of the tabs.  The code I posted earlier returned the list in the order as given in the drawing.

Code: [Select]
(vlax-map-collection
    (*layouts*)
    '(lambda (x) (setq lst (cons x lst)))
  )

This does what your code does.  (*layouts*) is a function I made to illustrate a point.  I normally use a global variable here.  If you are not familiar with vlax-map-collection think of mapcar for collections.  I think the syntax is different, but it works the same way.  The lambda function is the same as your while loop except mine does not filter out the "MODEL" tab yet.  I then called a sort function that uses the 'taborder property and once they were ordered I removed the first item which would be the "MODEL" tab.  Then you have an ordered list of tab objects.[/code]

I hope this helps and keep asking those questions. :D

SPDCad

  • Bull Frog
  • Posts: 453
Layout tab order
« Reply #10 on: March 03, 2005, 09:28:35 AM »
Thanks whdjr
 :D

I will take a better look at what you had posted and do some more experimentation now that I have access to CAD.

Thanks again for the help!
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

hendie

  • Guest
Layout tab order
« Reply #11 on: March 03, 2005, 09:37:25 AM »
or use LORG from resourcecad  :D

SPDCad

  • Bull Frog
  • Posts: 453
Layout tab order
« Reply #12 on: March 11, 2005, 02:11:14 PM »
I have been experimenting for days with all the ways suggested above and still come up with the same results.
Autocad retrieves the Tab layout bases on the order they where made, not the order they are displayed on screen! 
Oh, well that’s kill that lisp proggy!
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layout tab order
« Reply #13 on: March 11, 2005, 03:34:54 PM »
Here is a snipit of code from PlotTabs.lsp
Perhaps it will help you out.
Code: [Select]

  (setq plo_layouts
         (vla-get-layouts
           (vla-get-activedocument (vlax-get-acad-object))
         )
  )
  (vlax-for plo_layout plo_layouts ; get list of layout tabs
    (if (/= (setq tmpname (vla-get-name plo_layout)) "Model") ; omit MODEL space plot
      (if (not (and excludetab (vl-string-search excludechr tmpname)))
        (if (and (= plot-order "Tab") (not plottofile))
          ;; create with TabOrder numbers
          (setq plo_list (cons (cons (vla-get-taborder plo_layout)
                                     tmpname
                               ) ;_ end of cons
                               plo_list
                         ) ;_ end of cons
          )
          ;; else create list without TabOrder
          (setq plo_list (cons tmpname plo_list))
        ) ;_ endif
      ) ;_ endif
    ) ;_ endif
  ) ;_ end of vlax-for

  ;;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  (if plottofile
    (plot_to_file plo_list)
    ;; ELSE   -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    (progn ; plot to device
      (cond ; sort layout list
        ((= plot-order "Alpha")
         (setq plo_list (vl-sort plo_list '<))
        ) ; end cond 1
        ((= plot-order "Numeric")
         (setq plo_list (num_sort plo_list))
        ) ; end cond 2
        ((= plot-order "Tab")
         (setq plo_list
                (vl-sort plo_list
                         '(lambda (e1 e2) (< (car e1) (car e2)))
                ) ;_ end of vl-sort
         )
         (setq plo_list (mapcar 'cdr plo_list)) ;remove the taborder numbers
        ) ; end cond 3
      ) ; end cond

      (if revorder
        (setq plo_list (reverse plo_list))
      )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Layout tab order
« Reply #14 on: March 11, 2005, 04:29:44 PM »
SpdCad, the solution Will posted in reply #7 works for me.....I can reorder the tabs and it will give me the list in exatly the order they are displayed......