Author Topic: TabSort.lsp  (Read 87543 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
TabSort.lsp
« on: September 13, 2009, 02:53:03 PM »
Just a project I was working on recently, written for a bit of fun.

TabSort.lsp
Version 2.2

Code: [Select]
;;--------------------=={ TabSort.lsp }==---------------------;;
;;                                                            ;;
;;  A program designed with the intention to aid in the       ;;
;;  organisation of layout tabs in a drawing.                 ;;
;;                                                            ;;
;;  The program enables the user to organise each layout tab  ;;
;;  using buttons to move the tabs up, down, to the top, and  ;;
;;  to the bottom of a list.                                  ;;
;;                                                            ;;
;;  The user may rename any layout by double clicking on it,  ;;
;;  and can also add a Prefix and/or Suffix to selected/every ;;
;;  layout tab.                                               ;;
;;                                                            ;;
;;  The program offers the facility to add and delete a       ;;
;;  layout tab, and also sort the tabs alphabetically,        ;;
;;  numerically, architecturally; or reverse the order in     ;;
;;  which they appear.                                        ;;
;;                                                            ;;
;;  A Find and Replace function is incorporated to allow the  ;;
;;  user to quickly replace a text string in multiple tabs.   ;;
;;                                                            ;;
;;  The user can also Copy a layout tab, and set the Selected ;;
;;  layout tab as the current tab.                            ;;
;;                                                            ;;
;;  The Help Dialog can be access by pressing "H" at the Main ;;
;;  Dialog.                                                   ;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;                                                            ;;
;;  FUNCTION SYNTAX:  TABSORT                                 ;;
;;                                                            ;;
;;  Notes:-                                                   ;;
;;  The Reset button will reset Tab Order and Tab Names, but  ;;
;;  will not affect newly created tabs and will not recreate  ;;
;;  deleted tabs.                                             ;;
;;                                                            ;;
;;  In the case that multiple tabs are selected, the Current  ;;
;;  button will set the tab with the lowest index (highest in ;;
;;  the list) as the current tab.                             ;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;                                                            ;;
;;  With Thanks To:                                           ;;
;;  --------------------                                      ;;
;;  Gilles Chanteau (Gile)                                    ;;
;;                                                            ;;
;;  For his fantastic contribution to the list manipulation   ;;
;;  required for multiple DCL selections, and effort towards  ;;
;;  the Architectural Sort functions.                         ;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Charles Alan Butler (CAB)                                 ;;
;;                                                            ;;
;;  For his excellent idea to incorporate the Help button for ;;
;;  those who need it.                                        ;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Version:                                                  ;;
;;                                                            ;;
;;  1.0    -  13th September 2009                             ;;
;;                                                            ;;
;;  First Release                                             ;;
;;------------------------------------------------------------;;
;;  1.1    -  14th September 2009                             ;;
;;                                                            ;;
;;  Added Mnemonics to Tiles                                  ;;
;;  Added text to notify of double-click availability         ;;
;;  Added option to only pref/suff selected tab               ;;
;;------------------------------------------------------------;;
;;  1.2    -  15th September 2009                             ;;
;;                                                            ;;
;;  Added Numerical Sort                                      ;;
;;  General Bug Fixes                                         ;;
;;------------------------------------------------------------;;
;;  1.3    -  15th September 2009                             ;;
;;                                                            ;;
;;  Multi-tab Selection Functionality                         ;;
;;------------------------------------------------------------;;
;;  1.4    -  16th September 2009                             ;;
;;                                                            ;;
;;  Added Button to Set Current Tab                           ;;
;;  Added Copy Tab Functionality                              ;;
;;------------------------------------------------------------;;
;;  1.5    -  17th September 2009                             ;;
;;                                                            ;;
;;  Fixed Bug to Copy Layout Plot Settings                    ;;
;;------------------------------------------------------------;;
;;  1.6    -  18th September 2009                             ;;
;;                                                            ;;
;;  Modified Action_Tile Stmts ~ Thanks VovKa                 ;;
;;  Added Architectural Sort Button                           ;;
;;------------------------------------------------------------;;
;;  1.6.1  -  19th September 2009                             ;;
;;                                                            ;;
;;  Fixed Bugs ~ Thanks for feedback CAB                      ;;
;;------------------------------------------------------------;;
;;  1.7    -  20th September 2009                             ;;
;;                                                            ;;
;;  Added Find & Replace Functionality                        ;;
;;  Organised buttons/Added Sort Dialog                       ;;
;;------------------------------------------------------------;;
;;  1.7.1  -  20th September 2009                             ;;
;;                                                            ;;
;;  Replaced StrBrk sub with SplitStr (Gile)                  ;;
;;------------------------------------------------------------;;
;;  1.8    -  21st September 2009                             ;;
;;                                                            ;;
;;  Added hidden Help Button (CAB)                            ;;
;;  Added Help Dialog Definition                              ;;
;;------------------------------------------------------------;;
;;  1.8.1  -  22nd September 2009                             ;;
;;                                                            ;;
;;  General Bug Fixes                                         ;;
;;------------------------------------------------------------;;
;;  1.8.2  -  23rd September 2009                             ;;
;;                                                            ;;
;;  Fixed Bug causing crash when Deleting all                 ;;
;;  Tabs ~ thanks VovKa                                       ;;
;;------------------------------------------------------------;;
;;  1.9    -     2nd October 2009                             ;;
;;                                                            ;;
;;  Modified Reverse function to only apply to selected Tabs. ;;
;;  Altered Help Dialog to ok_only button                     ;;
;;------------------------------------------------------------;;
;;  2.0    -       22nd July 2010                             ;;
;;                                                            ;;
;;  Fixed Bug with Find/Replace.                              ;;
;;------------------------------------------------------------;;
;;  2.1    -    9th December 2010                             ;;
;;                                                            ;;
;;  Fixed Bug with Double Reversal                            ;;
;;------------------------------------------------------------;;
;;  2.2    -        16th May 2011                             ;;
;;                                                            ;;
;;  Program completely rewritten to update formatting.        ;;
;;  Upgraded Find & Replace engine to allow for               ;;
;;  self-referencing find and replace terms and improved      ;;
;;  visual feedback.                                          ;;
;;  Updated list manipulation subfunctions.                   ;;
;;------------------------------------------------------------;;

Program Controls:


Top: Move selected Tabs to the top of the list.


Up: Move selected Tabs up one notch in the list.


Down: Move selected Tabs down one notch in the list.


Bottom: Move selected Tabs to the bottom of the list.


Sort: Opens the Sort Dialog:



Alphabetical: Sort Tabs alphabetically:

Hence ~  
Code: [Select]
("A23" "C22" "B3" "E7")Becomes ~
Code: [Select]
("A23" "B3" "C22" "E7")
Numerical:  Sort Tabs numerically:

Hence ~  
Code: [Select]
("A23" "C22" "B3" "E7")Becomes ~
Code: [Select]
("B3" "E7" "C22" "A23")
Architectural:  Use an Architectural Sorting Method:

Hence ~  
Code: [Select]
("A-1A" "B-3" "A-10C" "B-1.2" "B-1")Becomes ~
Code: [Select]
("A-1A" "A-10C" "B-1" "B-1.2" "B-3")

Reverse:  Reverse the Tab order of Selected Tabs.


Pref/Suff:  Opens the Prefix/Suffix Dialog to allow the user to add a Prefix and/or Suffix to selected/all Tabs.




Add:  Add a new layout Tab.


Delete:  Deletes selected Tabs.


Copy:  Copies the selected Tabs.


Current:  Makes the selected Tab the Current Tab.


Find:  Allows the user to perform a Find & Replace:




Done: Finished sorting Tabs, will implement sorting.


Reset:  Will reset Tab names and Tab order  ~ will not reset deleted/added Tabs.


Screenshot:




Your comments/criticism is always welcome, and, of course, the inevitable bug reports!  8-)

Enjoy!  :-)

Lee


Full Description here
« Last Edit: May 17, 2011, 08:47:48 AM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #1 on: September 13, 2009, 03:23:40 PM »
Nice job Lee.
Here is my old routine: http://www.theswamp.org/index.php?topic=6511.0

Need to update it as this sort does a better job with Architectural tab names.
http://www.theswamp.org/index.php?topic=6474.0
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.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #2 on: September 13, 2009, 04:45:04 PM »
Thanks Alan  8-)

I thought that someone would have done this already - but I had fun in making it  ;-)


alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: TabSort.lsp
« Reply #3 on: September 13, 2009, 04:50:56 PM »
Nice functionality. I like all the options.

Comments:
1. Add a piece of text to the dialog to inform the user of the option to rename by double-clicking.
2. Utilizes a few of the bonus tool, I mean express tool functions. You could have a check at the beginning to ensure ET is loaded.
3. vla-get-activedocument and vlax-get-acad-object are called a few times.
4. You have a lot of subs that are not localized, not really a problem, except that I've noticed the DCL_Write function used by you quite a bit. If a user is running another program utilizing DCL_Write, problems are going to occur.

With that being said, I will, again say that I really like the program and will be adding it to my tool belt. Thanks for sharing.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #4 on: September 13, 2009, 05:51:06 PM »
Lee the double click is a great feature. I also like the prefix/suffix options.
I'll have to add those to my TabMover! :)

Notice on mine you may select a group of tabs. This would be useful when adding prefix/suffix to a selected group.
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.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #5 on: September 13, 2009, 06:54:35 PM »
Lee the double click is a great feature. I also like the prefix/suffix options.
I'll have to add those to my TabMover! :)

Notice on mine you may select a group of tabs. This would be useful when adding prefix/suffix to a selected group.


Thanks Alan - I had a bit of help with the double click from Andrea in the other recent thread - but I'm surprised that the list_box doesn't have an attribute already in place to aid with this functionality - all I could find was allow_accept...

I think the multiple selection of tabs is the next logical step for this - although it may mean a major overhaul in the coding... but thanks for the comments :-)

Nice functionality. I like all the options.

Thanks Al  8-)

1. Add a piece of text to the dialog to inform the user of the option to rename by double-clicking.

Good idea, I was thinking the same thing - I didn't want to spoil the "clean" look of the dialog, but I think it should be added.

2. Utilizes a few of the bonus tool, I mean express tool functions. You could have a check at the beginning to ensure ET is loaded.

There is a check at the top of the LISP - using the variable "et:wink:

3. vla-get-activedocument and vlax-get-acad-object are called a few times.

I only call it once actually, and use lexical scoping (got that term from Se7en :P ) to prevent calling it loads of times  :-)

4. You have a lot of subs that are not localized, not really a problem, except that I've noticed the DCL_Write function used by you quite a bit. If a user is running another program utilizing DCL_Write, problems are going to occur.

Ahh, yes - that could cause a problem, I may include the DCL_Write function within the Main Function definition and localise it.

With that being said, I will, again say that I really like the program and will be adding it to my tool belt. Thanks for sharing.

Thanks Alan, I feel honoured  8-)


Willie

  • Swamp Rat
  • Posts: 958
  • Going nowhere slowly
Re: TabSort.lsp
« Reply #6 on: September 13, 2009, 07:07:32 PM »
Nicely done Lee!!  Very handy
Soli Deo Gloria | Qui Audet Adipiscitur
Windows 8  64-bit Enterprise | Civil 3D 2015 and 2016| ArcGIS 10.1
Yogi Berra : "I'd give my right arm to be ambidextrous."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: TabSort.lsp
« Reply #7 on: September 13, 2009, 07:18:52 PM »
Lee Response #:
1. Yeah, I don't know where you would put it. Just a thought.
2 & 3. I stand corrected, completely overlooked.
4. No reason not to, or at least add a prefix/suffix 'TabMover' to it.
Seriously, nice work.

Lee the double click is a great feature. I also like the prefix/suffix options.
I'll have to add those to my TabMover! :)

Notice on mine you may select a group of tabs. This would be useful when adding prefix/suffix to a selected group.


Thanks Alan - I had a bit of help with the double click from Andrea in the other recent thread - but I'm surprised that the list_box doesn't have an attribute already in place to aid with this functionality - all I could find was allow_accept...

I think the multiple selection of tabs is the next logical step for this - although it may mean a major overhaul in the coding... but thanks for the comments :-)

Nice functionality. I like all the options.

Thanks Al  8-)

1. Add a piece of text to the dialog to inform the user of the option to rename by double-clicking.

Good idea, I was thinking the same thing - I didn't want to spoil the "clean" look of the dialog, but I think it should be added.

2. Utilizes a few of the bonus tool, I mean express tool functions. You could have a check at the beginning to ensure ET is loaded.

There is a check at the top of the LISP - using the variable "et"  :wink:

3. vla-get-activedocument and vlax-get-acad-object are called a few times.

I only call it once actually, and use lexical scoping (got that term from Se7en :P ) to prevent calling it loads of times  :-)

4. You have a lot of subs that are not localized, not really a problem, except that I've noticed the DCL_Write function used by you quite a bit. If a user is running another program utilizing DCL_Write, problems are going to occur.

Ahh, yes - that could cause a problem, I may include the DCL_Write function within the Main Function definition and localise it.

With that being said, I will, again say that I really like the program and will be adding it to my tool belt. Thanks for sharing.

Thanks Alan, I feel honoured  8-)


Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #8 on: September 13, 2009, 08:52:00 PM »
Nicely done Lee!!  Very handy

Thanks Willie  :-)

Lee Response #:
1. Yeah, I don't know where you would put it. Just a thought.
2 & 3. I stand corrected, completely overlooked.
4. No reason not to, or at least add a prefix/suffix 'TabMover' to it.
Seriously, nice work.

Cheers Alan, I'll see to those improvements :-)

I'm glad you like it mate  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: TabSort.lsp
« Reply #9 on: September 13, 2009, 10:01:17 PM »
Nicely done Lee!!  Very handy

Thanks Willie  :-)

Lee Response #:
1. Yeah, I don't know where you would put it. Just a thought.
2 & 3. I stand corrected, completely overlooked.
4. No reason not to, or at least add a prefix/suffix 'TabMover' to it.
Seriously, nice work.

Cheers Alan, I'll see to those improvements :-)

I'm glad you like it mate  :-)
This will be strike 3 for me today, I went back and looked at Alan's (Cab) Dcl2Lisp and you are working on the same principals. I found and have been using his since 07, without any issues. Just ignore what I've said. Probably just that I like to localize as many of my functions as possible. I do have a folder of them (ones I've written for day-to-day use) that I have loaded at every startup. That way, I can act as if they're additional commands in Autocad (sadly, you can't register lisp subs in Vlide), everything gets to use the most updated version of the sub. and I don't have to place them in each program file.

I forgot to mention it, but the ability to add a new layout was genius (should switch to newly created one though).

Hmm, that brings up an interesting question: I wonder if it's possible to replicate the 'copy layout' option (probably not in Lisp). I think I'll do a little research and digging.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Aerdvark

  • Guest
Re: TabSort.lsp
« Reply #10 on: September 14, 2009, 04:27:30 AM »
Hi Lee,

This is a great piece of coding ! Thank you for sharing it with us.You know I'm not that great of a programmer so I will only judge it by the functionality.

First of all I wonder; how did you come up with the idea? I know you study math and you are no drafter. Are you inspecting the screen for items to modify in a rondom way?  :lol:

95% of my project (*.dwg's) contain more than 3 layouts. Some of them contain like 20 layouts and I know there are people amongst us that go far beyond 20  :ugly:. Whenever I want to sort or rename it takes time. Therefore this routine comes in handy, ie. if in modelspace, it stays in modelspace.

In fact I have no comments on the routine itself. You might add some functions, like:

1. the use of the "CTRL" key so one can select multiple layouts to edit / sort.

2. I made myself a routine that helps adding template layouts. You might want to put that in yours too for that is mighty handy!!

Code: [Select]
(defun c:nlay( / size name)

(setq size (getstring (strcat "\nWhat size do you want your new layout to be ?? :  ")))
(setq name (getstring T (strcat "\nPlease give a name for the new layout :  ")))
(command "-layout" "t" "standards.dwg" size)
(command "-layout" "r" size name)
(princ)
);

Well, first there should be a dwg called "standards.dwg" in a supported path. Next: the file itself should contain several layouts as you want them to be. Name the various layouts ie. ISOA1 or ISOA2...  :|... me telling you how it works...

If you would add it, it would be great to have a drop down list in wich all the available "sizes" (layouts in the standards.dwg) are selectable, maybe even multiple selection...

3. A "cancel" button to finish the dialog?

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #11 on: September 14, 2009, 07:41:37 AM »
I forgot to mention it, but the ability to add a new layout was genius (should switch to newly created one though).

Thanks Alan - I think I'll make that change also.

Hmm, that brings up an interesting question: I wonder if it's possible to replicate the 'copy layout' option (probably not in Lisp). I think I'll do a little research and digging.

I think you would have to manually copy all the objects from the layout space into the new layout... I don't think there would be an elegant solution to it.  :|

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #12 on: September 14, 2009, 07:47:54 AM »
This is a great piece of coding ! Thank you for sharing it with us.You know I'm not that great of a programmer so I will only judge it by the functionality.

First of all I wonder; how did you come up with the idea? I know you study math and you are no drafter. Are you inspecting the screen for items to modify in a rondom way?  :lol:

95% of my project (*.dwg's) contain more than 3 layouts. Some of them contain like 20 layouts and I know there are people amongst us that go far beyond 20  :ugly:. Whenever I want to sort or rename it takes time. Therefore this routine comes in handy, ie. if in modelspace, it stays in modelspace.

Hey Marco, thanks for your comments, I'm glad you like the program  :-)

I'm not sure how I came up with the idea.. I find ideas hard to come by, and, like most things in programming - its all been done before (as CAB has demonstrated above...). So when an idea does pops into my head, I write it for a bit of fun.  ;-)

1. the use of the "CTRL" key so one can select multiple layouts to edit / sort.

Yes, I think this is the next step for this program - but it will be a lot more work I think...

3. A "cancel" button to finish the dialog?

I considered this...  but some of the changes (eg the delete tab option) occur as soon as the user has confirmed it - so I would have to implement the UNDO command quite a lot...

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #13 on: September 14, 2009, 09:56:11 AM »
Code in first post updated to reflect Version 1.1 ~ changes noted  :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #14 on: September 14, 2009, 10:29:37 AM »
Just updated a minor bug in the code to switch to the new tab when the user clicks "Add".