TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on August 22, 2005, 07:43:46 PM

Title: New Tab Order with TabMover.lsp
Post by: CAB on August 22, 2005, 07:43:46 PM
This is the "First Draft' if you will of a routine to rearrange the tab order.
The dialog box must be in the ACAD path.
Highlight a tab in the pick list then use the Up/Down buttons to move it.
Continue with other picks until you have the order you want the select the
Finished button.

I only have a few hours into it so there is a lot of cleanup to do yet but
I thought I would get some feed back before I go for round 2.
So if you don't mind alpha testing :) have a go with it.
I did limited testing in ACAD2000 only.


Code updated, see later message.
Title: New Tab Order with TabMover.lsp
Post by: Crank on August 23, 2005, 05:32:16 AM
Seems to be OK, because I can't find any bugs. :)

Perhaps it's an idea to move more tabs at once (with CTRL pressed) or to add some buttons for sorting the tabs. Just like you did in PlotTabs.
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 23, 2005, 01:33:08 PM
Thanks Crank for the suggestions.

Here is round 2.
Code: [Select]
;;;  [Buttons]
;;;  [First   ] Move the tab to top of list
;;;  [Up      ] Move the tab up one
;;;  [Insert  ] Insert the tab at a new location
;;;  [Down    ] move the tab down one
;;;  [Last    ] Move the tab to bottom of list
;;;  [Alphabet] Sort the list Alphabetically
;;;  [Invert  ] Invert the order
;;;  [Finished] Apply the changes to the tabs
;;;  [Cancel  ] Quit without changes


Insert works like this, select a tab to move. Press the Insert button.
All other tab buttons are dimmed. Select the tab you wish to insert the
tab on top of.

(http://www.theswamp.org/screens/cab/TabMover01.png)
Code: [Select]
;;;       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;       +                  TabMover.lsp                          +
;;;       +            Created by C. Alan Butler                   +
;;;       +               Copyright  2005                          +
;;;       +   by Precision Drafting & Design All Rights Reserved.  +
;;;       +    Contact at ab2draft@TampaBay.rr.com                 +
;;;       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;
;;; FUNCTION
;;; Dialog box to rearrange the tab order
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; tabmover
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;;
;;; VERSION
;;; 1.01 Aug 23, 2005
;;;
;;;
;;;  [Buttons]
;;;  [First   ] Move the tab to top of list
;;;  [Up      ] Move the tab up one
;;;  [Insert  ] Insert the tab at a new location
;;;  [Down    ] move the tab down one
;;;  [Last    ] Move the tab to bottom of list
;;;  [Alphabet] Sort the list Alphabetically
;;;  [Invert  ] Invert the order
;;;  [Finished] Apply the changes to the tabs
;;;  [Cancel  ] Quit without changes
;;;
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;                                                                    ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice below appear in all supporting documentation.              ;


(defun c:tabmover (/ dclfile dcl# action ptr
                   move load_list dialog_data doit)
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;                      Local Functions                          
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-

  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;                  Move the tab within the list                  
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (defun move (ptr newptr layouts / idx tmp tab)
    (cond
      ((= ptr newptr) ; no action
       ) ; cond 1
      ;; move up or down one in list
      ((or (= (1+ ptr) newptr) (= (1+ newptr) ptr))
        (setq idx (length layouts))
        (while (> (setq idx (1- idx)) -1)
          (if (or (= idx ptr) (= idx newptr))
            (setq tmp (cons (nth (min ptr newptr) layouts) tmp)
                  tmp (cons (nth (max ptr newptr) layouts) tmp)
                  idx  (1- idx)
            )
            (setq tmp (cons (nth idx layouts) tmp))
          )
        )
        (setq layouts tmp)
      ) ; cond 2
      (T ; move to newptr location
        (setq idx (length layouts)
              tab (nth ptr layouts))
        (while (> (setq idx (1- idx)) -1)
          (cond
            ((= idx ptr) ; skip the removed tab
             ()
            )
            ((= idx newptr) ; add the moved tab
             (setq tmp (cons (nth idx layouts) tmp)
                   tmp (cons tab tmp))
            )
            ((and (= newptr (length layouts))
                  (= idx (1- (length layouts)))); move to bottom
             (setq tmp (cons tab tmp)
                   tmp (cons (nth idx layouts) tmp))
            )
            (t
             (setq tmp (cons (nth idx layouts) tmp))
            )
          )
        )
        (setq layouts tmp)
      ) ; cond 3
    ); end cond stmt
    layouts
  ) ; end defun

  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;                    Load the layout list                        
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (defun load_list (layouts cur_tab / n one)
    (start_list "layouts")
    (foreach one layouts
      (add_list one)
    )
    (end_list)
    (if (setq n (vl-position cur_tab layouts))
      (set_tile "layouts" (itoa n))
      (set_tile "layouts" "0")
    )
  ) ; end defun


  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;                       Load dialog actions                      
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (defun dialog_data (ptr layouts ins_on)
    (load_list layouts (nth ptr layouts))
    (action_tile "UP" "(Setq Action 1)(done_dialog 5)")
    (action_tile "DN" "(Setq Action 2)(done_dialog 5)")
    (action_tile "top" "(Setq Action 3)(done_dialog 5)")
    (action_tile "bot" "(Setq Action 4)(done_dialog 5)")
    (action_tile "ins" "(Setq Action 5)(done_dialog 5)")
    (action_tile "srt" "(Setq Action 7)(done_dialog 5)")
    (action_tile "inv" "(Setq Action 8)(done_dialog 5)")
    (action_tile "ok" "(Setq Action -1)(done_dialog 5)")
    (action_tile "cancel" "(Setq Action 0)(done_dialog 1)")
    (if ins_on
      (progn
        (action_tile "layouts" "(setq ptr (ATOI $value) Action 6)(done_dialog 5)")
        (mode_tile "UP" 1)  ;disabled
        (mode_tile "DN" 1)  ;disabled
        (mode_tile "top" 1) ;disabled
        (mode_tile "bot" 1) ;disabled
        (mode_tile "srt" 1) ;disabled
        (mode_tile "inv" 1) ;disabled
        (set_tile "txt1" "*** Now select the tab where the insert will be inserted ***")
        (set_tile "txt2" "*** Or press the Insert button to cancel this insert   ***")
      )
      (progn
        (action_tile "layouts" "(setq ptr (ATOI $value))")
        (mode_tile "UP" 0)  ;enabled
        (mode_tile "DN" 0)  ;enabled
        (mode_tile "top" 0) ;enabled
        (mode_tile "bot" 0) ;enabled
        (mode_tile "srt" 0) ;enabled
        (mode_tile "inv" 0) ;enabled
        (set_tile "txt1" "INSERT: Select a tab to move, press insert button, select")
        (set_tile "txt2" "where to insert in list or Insert again to cancel")
      )
     )
  ) ; end defun


  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;                     Run the Dialog                            
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (defun doit (dcl_id / x y layouts vlayouts ptr action doc one tmp
               cnt newptr ins_on)
    ;; get tab names, sort in tab order & remove model
    (vlax-map-collection
      (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      '(lambda (x) (setq vlayouts (cons x vlayouts)))
    )
    ;;  sort in tab order & remove model
    (setq vlayouts (cdr (vl-sort vlayouts
                            '(lambda (x y)
                               (< (vla-get-taborder x) (vla-get-taborder y))
                             )
                   ))
    )
    ;;  make list of names into strings  remove Model space
    (setq layouts (mapcar '(lambda (x) (vla-get-name x)) vlayouts))
   
    (setq ptr 0) ; start at the top of the list
    (dialog_data ptr layouts ins_on) ; actions

    (setq do_dialog t) ; flag loop to start

    ;;  repeat dialog until user exits
    (while do_dialog
      ;;  Start Dialog Box
      (if (= (setq tmp (start_dialog)) 5) ; temp exit of dialog
        (progn
          (cond
            ((= action 1) ; move_up
             (setq newptr (max (1- ptr) 0)
                   layouts (move ptr newptr layouts)
                   ptr newptr)
            ) ; end cond 1
            ((= action 2) ; move down
             (setq newptr (min (1+ ptr) (1- (length layouts)))
                   layouts (move ptr newptr layouts)
                   ptr newptr)
            ) ; end cond 2
            ((= action 3) ; move to top
             (setq newptr 0
                   layouts (move ptr newptr layouts)
                   ptr 0)
            ) ; end cond 3
            ((= action 4) ; move to bottom
             (setq newptr (length layouts)
                   layouts (move ptr newptr layouts)
                   ptr (1- (length layouts)))
            ) ; end cond 4
            ((= action 5) ; insert toggle
             ;;  after button is pressed get the next pointer location
             ;;  if button is pressed again before selection cancel insert
             (setq ins_on (not ins_on)
                   newptr ptr) ; save pointer
            ) ; end cond 5
            ((= action 6) ; insert
             ;;  ptr points to the new location, newptr points to the old location
             (setq layouts (move newptr ptr layouts)
                   ins_on nil)
            ) ; end cond 6
            ((= action 7) ; sort alpha
             (setq layouts (vl-sort layouts '<))
            ) ; end cond 7
            ((= action 8) ; invert list
             (setq layouts (reverse layouts))
            ) ; end cond 8
            ((= action -1) ; rearange the tabs
             (setq cnt 1
                   doc (vla-get-activedocument (vlax-get-acad-object))
             )
             (foreach one layouts
               (vla-put-taborder (vla-item (vla-get-layouts doc) one) cnt)
               (setq cnt (1+ cnt))
             )
            ) ; end cond 9
          ) ; end cond stmt
          (if (> action 0)
            (progn
              ;;  restart the dialog box
              (new_dialog "tabmover" dcl_id)
              (dialog_data ptr layouts ins_on)
            ) ; progn
            ;;  ELSE user wants to quit
            (setq do_dialog nil)
          ) ; endif

        ) ; end progn
        ;;  ELSE user wants to quit
        (setq do_dialog nil)
      )
    ) ; endwhile
    (unload_dialog dcl_id)

  ) ; end defun


  ;;================================================================
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;================================================================
  ;;                    Start of Routine                            
  ;;================================================================
  ;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;================================================================
  (vl-load-com)

  (setq dclfile "tabmover.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) ; Error
     (prompt (strcat "\nCannot load " dclfile "."))
    )
    ((not (new_dialog "tabmover" dcl#)) ; Error
     (prompt (strcat "\nProblem with " dclfile "."))
    )
    (t ; No DCL problems: fire it up
     (doit dcl#)
    ) ; end cond T
  ) ; end cond
  (princ)
) ; end defun main

(prompt "\n***---  Tab Mover Loaded, type Tabmover to run  ---***")
(princ)



Save this as TabMover.dcl in the ACAD search path.
Code: [Select]
dcl_settings : default_dcl_settings { audit_level = 3; }

tabmover : dialog {
    label = "   Tab Mover by CAB v1.01";
    : boxed_row {
        label = "< Tabs >";
        : list_box {
            key = "layouts";
            width = 30;
            height = 20;
        }
        : column {
            : button {
                label = "First";
                key = "top";
                mnemonic = "F";
            }
            : button {
                label = "Up";
                key = "UP";
                mnemonic = "U";
            }
            : button {
                label = "Insert";
                key = "ins";
                mnemonic = "I";
            }
            : button {
                label = "Down";
                key = "DN";
                mnemonic = "D";
            }
            : button {
                label = "Last";
                key = "bot";
                mnemonic = "L";
            }
            : spacer {
                height = 2;
            }
            : button {
                label = "Alphabetical";
                key = "srt";
                mnemonic = "A";
            }
            : button {
                label = "inVert";
                key = "inv";
                mnemonic = "V";
            }
        }
    }
    : text { key = "txt1" ;
             width = 65 ;
             alignment = centered ; }
    : text { key = "txt2" ;
             width = 65 ;
             alignment = centered ; }
   : row {
    : button {
        label = "Finished";
        key = "ok";
        mnemonic = "F";
        // fixed_width = true ;
    }
    : cancel_button {}
    }
}
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 23, 2005, 02:32:36 PM
Very nice routine CAB.  I like everything you have included.  I have 2 suggestions for you to think about:

1.  Let the listbox allow multiple selection so a user can move a group of tabs together.

2.  Allow the user to sort either alpha or numericly first.

Good job!
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 23, 2005, 02:33:25 PM
3.  Maybe make the listbox a little bit wider.

 :)
Title: New Tab Order with TabMover.lsp
Post by: Crank on August 23, 2005, 02:41:52 PM
Less is more...
I don't see any use of the invert button.
The insert button works good, but is to difficult to understand without explaning.

@ Will:
1 That's what I mean with the CTRL-button.
2 I agree
3 maybe something like this:
Code: [Select]

dcl_settings : default_dcl_settings { audit_level = 3; }

tabmover : dialog {
    label = "   Tab Mover by CAB v1.01";
    : boxed_row {
        label = "< Tabs >";
        : list_box {
            key = "layouts";
            width = 25;
            height = 20;
        }
        : column {
            : button {
                label = "First";
                key = "top";
                mnemonic = "F";
            }
            : button {
                label = "Up";
                key = "Up";
                mnemonic = "U";
            }
            : button {
                label = "Down";
                key = "DN";
                mnemonic = "D";
            }
            : button {
                label = "Last";
                key = "bot";
                mnemonic = "L";
            }
            : spacer {
                height = 2;
            }
            : button {
                label = "Alphabetical";
                key = "srt";
                mnemonic = "A";
            }
            : button {
                label = "Numeric";
                key = "srt_num";
                mnemonic = "N";
            }
        }
    }
    : row {
    }
    : button {
        label = "Finished";
        key = "ok";
        mnemonic = "F";
    }
    : cancel_button {}
}
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 23, 2005, 02:44:58 PM
Sorry for stepping on your comments Crank.  I didn't even see your post. :shock:
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 23, 2005, 03:02:37 PM
Will, thanks for the reply.
You must have long tab names. I keep the short myself.
Or were you talking about the asthectics of the box?

Group selections are easy to impliment on the pick lisst but add some complecited
in the routine. I'm sure you know all about that.
I usually have 6 to 10 tabs in a drawing but reading post here I see some people
have large number of tabs. So for them I guess a multi select may be useful.

You can sort at any time and keep munipulating the list as you like until you
are satisfied with the list.
Do you think numerical sort is needed?

Crank, I like it..  nice touch with the mnemonics.
I added the image next to the old one above to compare.
Do you think the numeric sort is needed?
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 23, 2005, 03:41:49 PM
Most of tab names are the sheet name followed by a hypen with a short description.  We may have upwards of 50 so it helps on navigation.  Also the box just looked a little skinny too.

I wouldn't use the numerical sort (that I know of) here but others might find it usefull.  I just thought the functionality would be good for others.

Good job on the tool.
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 23, 2005, 04:37:54 PM
Thanks Will,
I updated the screen shot again.
Fattened the box a little more, traded the numeric sort for invert.
Not that anyone will need the invert, I may loose that too.
I'll post the updated code in a few.
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 23, 2005, 04:47:09 PM
Ok, there is the new code.
I have not addresses the Milti-selection option yet.
I need to do some work today, so it will have to wait. :(
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 23, 2005, 05:39:22 PM
Changed the code once more, added a dynamic text message to explain the INSERT
function, it changes when you start the command.
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 24, 2005, 01:26:52 PM
Here is the Multi-Select Version.
TabMover.zip (http://theswamp.org/lilly_pond/cab/TabMover082505.zip?nossi=1)

Code: [Select]
;;;   The pick box allows Multi-seletions. This is accomplished with the
;;;   Shift and Ctrl keys. To select sententially just left click & drag
;;;   the pointer over the selections or click the one end of the list to
;;;   be selected then Shift Click the other end. To select non sequential
;;;   items use the Ctrl Key and Ctrl left click the items to be added to
;;;   the selection.  Pick the Insert Button to cash this list of selected
;;;   items. Then pick in the list to identify the insert point. That item
;;;   will be pushed down &  the list inserted.


I tested but you know how that goes. :)
Please report any anomalies, better known as bugs. 8)

Thanks
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 24, 2005, 05:30:57 PM
CAB,

I like the new multi-select version.  My first thought was 'This suck!' when I selected a group of tabs and clicked down and then my selectionset was gone.  But after looking at and reading about the insert option I think I like it.

It's pretty nice.

Have you tried it on any other version yet?  I'll try on 2006 and see if it works.
Title: New Tab Order with TabMover.lsp
Post by: whdjr on August 24, 2005, 05:35:56 PM
Okay CAB,  I tried it in 2006 and it works great.

I tried some of the options with multi-select and they all work great.  All the buttons work with just your selection --- pretty KOOL stuff :dood:  :dood:
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 24, 2005, 06:13:17 PM
Thanks for the kind words Will. :)
Glad you like it.

My plan was to add the DCL installer code so it will install the DCL file for you.
That is when the tweaking is done. And that may be now.

Lots of people looking but not much feed back. I though more people would like a
tool like this. I go so tired of the "Move To End" method. That's why I wrote the
routine.

The Multi-select is kinda cool. Have you tried to select two groups at once using
the Ctrl key? When you move them the groups are combined and placed in the destination
leaving the unselected item in place. i got a kick out of it. :oops:

I'll post the final version over in 'Show Your Stuff' when i add the DCl loader.

Thanks to you and Crank for the help.  Works in 2004 also.
Title: New Tab Order with TabMover.lsp
Post by: Jeff_M on August 24, 2005, 08:12:05 PM
Hi Alan,
I'm one of those looking, but I haven't had a need to try it. Most of my projects are setup with the correct number of layouts, so I usually wouldn't need something like this. I've been watching, though, just to see what you've come up with. I enjoy watching the evolution of a project, even when I don't have any input for it.

It looks like you've got yourself a winner, based on what Will & Crank have said.

When I do get some time to play, I will be checking it out though. :)
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 24, 2005, 09:55:54 PM
Thanks for the input Jeff,
It is interesting how varied the drawing environment are from user to user.
Like Will with some 50 layouts & you with the layouts already set up.
I usually use a template drawing with most of the layouts already there and
in the proper order but there seems to always be that exception. I don't expect
to use the routine but once or twice a month which may not justify writing it.
But it will be enjoyable when i do use it just because the other method of moving
layouts always irritated me. :?

See ya..
Title: New Tab Order with TabMover.lsp
Post by: MP on August 24, 2005, 10:05:42 PM
I don't have a need for such a utility but I downloaded it and took it for a spin just for fun. Pretty cool stuff Alan. For those that draft all day and use a lot of tabs I can see how this would be very useful. Excellent work!

Discardable minor suggestion: Putting the 'Hint text' at the top of the dialog will make it more visible, as one's eye is already drawn to the top of the list box to view the tab names. As is one kinda looks up and down.

(http://www.theswamp.org/screens/mp/tabmover.png)

Cheers and again, nice work.

:)
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 24, 2005, 11:45:00 PM
Thanks for the test drive and the suggestion.
You have an artistic flair in your code & your dialog.
I like your suggestion so I'll use it. :)
Title: New Tab Order with TabMover.lsp
Post by: Crank on August 25, 2005, 02:20:49 PM
The new multi-select version is great.

Found a bug though: If you select several tabs with 1 unselected line between the groups and press 'down' the selected tabs disappear from the list...
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 25, 2005, 03:06:07 PM
Thanks Crank, I'm on it...
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 25, 2005, 04:57:36 PM
Try This TabMover082505.zip (http://theswamp.org/lilly_pond/cab/TabMover082505.zip?nossi=1)

Code updated, link removed, see next post.
Title: New Tab Order with TabMover.lsp
Post by: CAB on August 27, 2005, 12:57:28 PM
OK, posted the code over here http://www.theswamp.org/phpBB2/viewtopic.php?p=79791#79791

Added the auto DCL file creator so delete the old DCL file.
Also added the Numeric sort routine, see this for more on that routine. http://www.theswamp.org/phpBB2/viewtopic.php?t=6474