TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on September 13, 2009, 02:53:03 PM

Title: TabSort.lsp
Post by: Lee Mac 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:

(http://www.theswamp.org/screens/leemac/TopButton.png)
Top: Move selected Tabs to the top of the list.

(http://www.theswamp.org/screens/leemac/UpButton.png)
Up: Move selected Tabs up one notch in the list.

(http://www.theswamp.org/screens/leemac/DownButton.png)
Down: Move selected Tabs down one notch in the list.

(http://www.theswamp.org/screens/leemac/BottomButton.png)
Bottom: Move selected Tabs to the bottom of the list.

(http://www.theswamp.org/screens/leemac/Sort.Button.png)
Sort: Opens the Sort Dialog:

(http://www.theswamp.org/screens/leemac/Sort.png)

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")
(http://www.theswamp.org/screens/leemac/ReverseButton.png)
Reverse:  Reverse the Tab order of Selected Tabs.

(http://www.theswamp.org/screens/leemac/PrefSuffButton.png)
Pref/Suff:  Opens the Prefix/Suffix Dialog to allow the user to add a Prefix and/or Suffix to selected/all Tabs.

(http://www.theswamp.org/screens/leemac/PrefSuffd.png)

(http://www.theswamp.org/screens/leemac/AddButton.png)
Add:  Add a new layout Tab.

(http://www.theswamp.org/screens/leemac/DeleteButton.png)
Delete:  Deletes selected Tabs.

(http://www.theswamp.org/screens/leemac/CopyButton.png)
Copy:  Copies the selected Tabs.

(http://www.theswamp.org/screens/leemac/CurrentButton.png)
Current:  Makes the selected Tab the Current Tab.

(http://www.theswamp.org/screens/leemac/Find.png)
Find:  Allows the user to perform a Find & Replace:

(http://www.theswamp.org/screens/leemac/F%26R.png)

(http://www.theswamp.org/screens/leemac/DoneButton.png)
Done: Finished sorting Tabs, will implement sorting.

(http://www.theswamp.org/screens/leemac/ResetButton.png)
Reset:  Will reset Tab names and Tab order  ~ will not reset deleted/added Tabs.


Screenshot:

(http://lee-mac.com/lisp/gifs/TabSort15.png)


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

Enjoy!  :-)

Lee


Full Description here (http://lee-mac.com/tabsort.html)
Title: Re: TabSort.lsp
Post by: CAB 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
Title: Re: TabSort.lsp
Post by: Lee Mac 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  ;-)

Title: Re: TabSort.lsp
Post by: alanjt 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.
Title: Re: TabSort.lsp
Post by: CAB 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.
Title: Re: TabSort.lsp
Post by: Lee Mac 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-)

Title: Re: TabSort.lsp
Post by: Willie on September 13, 2009, 07:07:32 PM
Nicely done Lee!!  Very handy
Title: Re: TabSort.lsp
Post by: alanjt 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-)


Title: Re: TabSort.lsp
Post by: Lee Mac 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  :-)
Title: Re: TabSort.lsp
Post by: alanjt 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.
Title: Re: TabSort.lsp
Post by: Aerdvark 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?
Title: Re: TabSort.lsp
Post by: Lee Mac 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.  :|
Title: Re: TabSort.lsp
Post by: Lee Mac 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...
Title: Re: TabSort.lsp
Post by: Lee Mac on September 14, 2009, 09:56:11 AM
Code in first post updated to reflect Version 1.1 ~ changes noted  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac 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".
Title: Re: TabSort.lsp
Post by: T.Willey on September 14, 2009, 11:16:27 AM
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.  :|

Just use the ' CopyObjects ' method of the document.  You might have to turn on viewports in the new layout, but you should be able to copy all content from one tab to another, even if it is one you just created.  Just make sure you don't grab the very first viewport, as that is the paperspace viewport.
Title: Re: TabSort.lsp
Post by: jmcshane on September 14, 2009, 11:25:56 AM
Lee,
That is a real timesaver. Nice one.

I have just tried it on Civil 3D 2009 but it didn't switch to the new tab whenever I hit the ADD button.

One question though?
Would it be possible to include a numerical sort as well as the Alpha, as in that it will show 99, 100, 101 in order?

Thanks for sharing.

John




Title: Re: TabSort.lsp
Post by: Lee Mac on September 14, 2009, 11:55:42 AM
Just use the ' CopyObjects ' method of the document.  You might have to turn on viewports in the new layout, but you should be able to copy all content from one tab to another, even if it is one you just created.  Just make sure you don't grab the very first viewport, as that is the paperspace viewport.

Thanks Tim - I'll certainly look into that method  8-)

Lee,
That is a real timesaver. Nice one.

I have just tried it on Civil 3D 2009 but it didn't switch to the new tab whenever I hit the ADD button.

One question though?
Would it be possible to include a numerical sort as well as the Alpha, as in that it will show 99, 100, 101 in order?

Thanks for sharing.

John

Hi John,

When you hit the "Add" button the program should highlight (select) the new tab in the list_box on the dialog - does this not happen?

I should think I could incorporate a Numerical Sort into the program in due course  :-)

Thanks for the comments, glad you like it  :-)

Lee
Title: Re: TabSort.lsp
Post by: jmcshane on September 14, 2009, 12:00:57 PM
Oops! :oops:
Yes it does, I was looking at the actual Tabs.

Sorry about that.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 14, 2009, 12:01:39 PM
Oops! :oops:
Yes it does, I was looking at the actual Tabs.

Sorry about that.

Not a problem John  :-)
Title: Re: TabSort.lsp
Post by: CHulse on September 14, 2009, 12:37:53 PM
That's great Lee, Thanks!

My only request would be to have the ability to select several (but not all) tabs to sort or apply a prefix/suffix.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 14, 2009, 12:41:00 PM
That's great Lee, Thanks!

My only request would be to have the ability to select several (but not all) tabs to sort or apply a prefix/suffix.

Thanks Cary  :-)

I'm working on the Multiple Tab Selection  :wink:
Title: Re: TabSort.lsp
Post by: CHulse on September 14, 2009, 12:42:47 PM
Sweet
Very useful
Title: Re: TabSort.lsp
Post by: alanjt on September 14, 2009, 12:44:44 PM
Just updated a minor bug in the code to switch to the new tab when the user clicks "Add".
;-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 14, 2009, 08:05:22 PM
I have updated the first post to include Version 1.2  ~ which now includes a Numerical Sort, hence:

Code: [Select]
("A32" "C23" "A22" "E7")

Becomes:

Code: [Select]
("E7" "A22" "C23" "A32")

Multiple Tab Selection coming soon  :-)

Enjoy!

Lee

Title: Re: TabSort.lsp
Post by: Aerdvark on September 15, 2009, 01:22:32 AM
Lee,

Thanks for reply.

What do you think of the "nlay" function I mentioned?
Wouldn't that be a nice add on?

V 1.2 looks nice to me. A handy tool I say. :kewl:
Title: Re: TabSort.lsp
Post by: Lee Mac on September 15, 2009, 07:26:40 AM
What do you think of the "nlay" function I mentioned?
Wouldn't that be a nice add on?

Thanks for the suggestion Marco, but I think I'd rather stay away from templates - that would make the program quite user specific, and I'd rather keep this pretty generic.  :-)

V 1.2 looks nice to me. A handy tool I say. :kewl:

Thanks Marco  :-)
Title: Re: TabSort.lsp
Post by: jmcshane on September 15, 2009, 09:28:20 AM
You beauty!

Excellent tool Lee.

Maybe if you get bored sometime, you could add in the facility to export to single drawings.

Thanks a million for sharing it. You are a legend.

Title: Re: TabSort.lsp
Post by: Lee Mac on September 15, 2009, 09:58:52 AM
Thanks John  8-)

When you say "export to single drawings" do you mean make each tab a new drawing?
Title: Re: TabSort.lsp
Post by: jmcshane on September 15, 2009, 10:20:09 AM
You are welcome.

Quote
When you say "export to single drawings" do you mean make each tab a new drawing?

Yeah, I know its a big task but this tool would then be the ultimate one stop shop for layout tabs.


How do you get the time to do all this code?





Title: Re: TabSort.lsp
Post by: Lee Mac on September 15, 2009, 10:27:33 AM
Quote
When you say "export to single drawings" do you mean make each tab a new drawing?

Yeah, I know its a big task but this tool would then be the ultimate one stop shop for layout tabs.

That would be a big task  :lol:  I'm currently working on the Multiple Tab Selection, so I'll see if I have the time  :-)

How do you get the time to do all this code?

I'm a uni student, on my summer break at the moment, I write the code between my studies and job  :-)
Title: Re: TabSort.lsp
Post by: jmcshane on September 15, 2009, 10:49:55 AM
Nice one.
Keep up the good work.
Title: Re: TabSort.lsp
Post by: T.Willey on September 15, 2009, 11:08:19 AM
Quote
When you say "export to single drawings" do you mean make each tab a new drawing?

Yeah, I know its a big task but this tool would then be the ultimate one stop shop for layout tabs.

That would be a big task  :lol:  I'm currently working on the Multiple Tab Selection, so I'll see if I have the time  :-)

This thread might help...

[ http://www.theswamp.org/index.php?topic=19721.0 ]
Title: Re: TabSort.lsp
Post by: Lee Mac on September 15, 2009, 11:30:21 AM
Thanks Tim - I'll check it out  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 15, 2009, 05:49:52 PM
First post now updated to include Version 1.3 now with the ability to select multiple tabs.

My sincere thanks go to Gile (and others) for his contribution to help make this a reality - related thread here (http://www.theswamp.org/index.php?topic=30304.0)

Enjoy  :-)

Lee
Title: Re: TabSort.lsp
Post by: haustab on September 16, 2009, 01:49:47 AM
Hallo Lee Mac,
Good job… RESPECT
Thanks for sharing.

Only a button to set a selected tab active/actual.
(a small thing  :wink:)
(setvar 'ctab selectedtab)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 05:49:37 AM
Thanks Haustab  :-)

I have a few other ideas, and that happened to be one of them also - just gotta find space for all the buttons :-D
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 11:46:17 AM
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.  :|

Just use the ' CopyObjects ' method of the document.  You might have to turn on viewports in the new layout, but you should be able to copy all content from one tab to another, even if it is one you just created.  Just make sure you don't grab the very first viewport, as that is the paperspace viewport.

Hi Tim,

I am currently attempting to add this feature to the program, but I am falling down when it comes to viewports.

When I try to filter the first viewport out, I end up with one viewport missing. But, if I do not filter out any objects, I end up with the Paperspace viewport, but still missing one of the user-drawn viewports...  :|

So, my question is, how can I tell which viewport to filter out in my:

Code: [Select]
(vlax-for Obj (vla-get-Block <layout>)
...

Advice is appreciated as always  :-)
Title: Re: TabSort.lsp
Post by: T.Willey on September 16, 2009, 11:53:06 AM
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.  :|

Just use the ' CopyObjects ' method of the document.  You might have to turn on viewports in the new layout, but you should be able to copy all content from one tab to another, even if it is one you just created.  Just make sure you don't grab the very first viewport, as that is the paperspace viewport.

Hi Tim,

I am currently attempting to add this feature to the program, but I am falling down when it comes to viewports.

When I try to filter the first viewport out, I end up with one viewport missing. But, if I do not filter out any objects, I end up with the Paperspace viewport, but still missing one of the user-drawn viewports...  :|

So, my question is, how can I tell which viewport to filter out in my:

Code: [Select]
(vlax-for Obj (vla-get-Block <layout>)
...

Advice is appreciated as always  :-)

The paper space viewport is the first object within the layout's block table record, so just skip the first item.

With that said, you can look at this thread for more information on viewports.  Lots of good info.
[ http://www.theswamp.org/index.php?topic=10992.0 ]

If more than a push is needed, let me know.  :wink:
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 01:36:09 PM
The paper space viewport is the first object within the layout's block table record, so just skip the first item.

With that said, you can look at this thread for more information on viewports.  Lots of good info.
[ http://www.theswamp.org/index.php?topic=10992.0 ]

If more than a push is needed, let me know.  :wink:

Thats what I thought - I tried a code that skipped the first item and got the same thing...

Thanks for the link - I see that Patrick's solution towards the end of the thread is almost identical to what I had tried as well.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 01:37:07 PM
Sussed!

OK, you do need the paperspace viewport!

But I forgot that my code was reversing the Object List - after keeping the Paperspace Viewport and reversing the list, all is fine  8-)
Title: Re: TabSort.lsp
Post by: T.Willey on September 16, 2009, 01:37:49 PM
If you still need help, post the code.  I would think all you have to do is make one list of all the items in the layout, then use the copyobjects method on said list, and be done with it.
Title: Re: TabSort.lsp
Post by: T.Willey on September 16, 2009, 01:38:28 PM
Sussed!

OK, you do need the paperspace viewport!

But I forgot that my code was reversing the Object List - after keeping the Paperspace Viewport and reversing the list, all is fine  8-)

Good to hear.  It's always the small items.  " The devil is in the details. " - Whoever....
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 01:43:54 PM
Sussed!

OK, you do need the paperspace viewport!

But I forgot that my code was reversing the Object List - after keeping the Paperspace Viewport and reversing the list, all is fine  8-)

Good to hear.  It's always the small items.  " The devil is in the details. " - Whoever....

So true - the feeling is great when you finally find it  8-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 02:03:42 PM
I have updated the first post to Version 1.4

Thanks Tim for your help in making this a reality  :wink:
Title: Re: TabSort.lsp
Post by: Willie on September 16, 2009, 06:36:55 PM
Very impressive Lee.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 16, 2009, 06:41:52 PM
Very impressive Lee.

Thanks Willie  :-)

I think I'm just about done with this one - not sure what else to add without making it look cluttered...  :|

Lee
Title: Re: TabSort.lsp
Post by: haustab on September 17, 2009, 01:30:18 AM
Thanks Lee,
Great job(s)
(like the other stuff you published)
Title: Re: TabSort.lsp
Post by: jmcshane on September 17, 2009, 04:02:29 AM
Quote
Your comments/criticism is always welcome, and, of course, the inevitable bug reports!

Lee,

This just gets better and better.

One thing though, The copy function, while it does copy the tab, does not copy the page setup information
as it does when copying the tab manually.

I hate to be picky considering the amount of work you have put into this, and there is now way you can keep everybody happy,
but I thought you would want to know.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 05:41:30 AM
Quote
Your comments/criticism is always welcome, and, of course, the inevitable bug reports!

Lee,

This just gets better and better.

One thing though, The copy function, while it does copy the tab, does not copy the page setup information
as it does when copying the tab manually.

I hate to be picky considering the amount of work you have put into this, and there is now way you can keep everybody happy,
but I thought you would want to know.


No worries John, I am happy for the criticism - that way things can be improved on  :-)

I shall definitely look into it, thanks for the comment.

Lee

Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 06:26:25 AM
I have updated the first post to version 1.5, this should resolve the issue with copying Plot settings.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 06:45:15 AM
Not sure whether this is necessary or not, but, with each version of the program, a DCL file is written to the AutoCAD filepath - if you want to clean the excess TabSort DCL files from the filepath, they are stored in the same location as the ACAD.pat file.

You can do a search for that file and delete the old DCL versions manually, else, I have written this short function that will clean it for you:

Code: [Select]
(defun c:TabSortClean (/ wPath)
  (vl-load-com)
  (if (setq wPath (findfile "ACAD.PAT"))
    (progn
      (setq wPath (vl-filename-directory wPath))
      (or (eq "\\" (substr wPath (strlen wPath)))
          (setq wPath (strcat wPath "\\")))
      (foreach file (vl-directory-files wPath "TabSortV1.*.dcl" 1)
        (initget "Yes No")
        (if (/= "No" (getkword (strcat "\nDelete file: " file " ? [Yes/No] <Yes> : ")))
          (vl-file-delete (strcat wPath file))))))
  (princ))

Authorisation is required before each deletion, so it won't just wipe them all at once  :wink:
Title: Re: TabSort.lsp
Post by: Willie on September 17, 2009, 07:30:26 AM
Hi Lee,

Can't you delete the temp dcl file when you close the dialog?
Title: Re: TabSort.lsp
Post by: jmcshane on September 17, 2009, 07:38:07 AM
I have updated the first post to version 1.5, this should resolve the issue with copying Plot settings.

Sorted.
Thanks Lee.
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 08:23:25 AM
Lee,
FYI, In architectural DWGs the tab names need to be sorted like this:
A1
A2
A3
A10
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 09:02:47 AM
Hi Lee,

Can't you delete the temp dcl file when you close the dialog?

I could do - but I felt it was better to write the file, and check if the file existed on the second time of invoking the function - instead of writing it every time the user invoked the command.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 09:04:07 AM
Lee,
FYI, In architectural DWGs the tab names need to be sorted like this:
A1
A2
A3
A10

My #Sort should sort them like that  :-)
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 09:31:11 AM
I don't think so. :evil:
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 10:25:33 AM
 :?  :?


(http://www.theswamp.org/screens/leemac/CAB.gif)
Title: Re: TabSort.lsp
Post by: Gliderider on September 17, 2009, 11:31:44 AM
Thanks Lee, I found it quite useful today!
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 12:14:43 PM
Thanks Lee, I found it quite useful today!

Your welcome Larry - I'm glad that I could help out  :-)
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 12:31:26 PM
Lee,
Sorry for my poor example, I did not type all the tabs I have.
A1
A2
A3
A10
E1
E2
M1
M2
Title: Re: TabSort.lsp
Post by: Gliderider on September 17, 2009, 12:52:09 PM
Try the Alpha sort, then the # sort, then the Alpha sort again
worked for me...
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 01:38:40 PM
Lee,
Sorry for my poor example, I did not type all the tabs I have.
A1
A2
A3
A10
E1
E2
M1
M2

Ahh, yes, mine will sort predominantly on Numbers - and then Alpha...

And, of course, the Alpha will make it:

A1 A10 A2 A3....
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 02:36:34 PM
I'm not sure that I want to completely replace my Numerical Sort with one that would sort the tabs in that order though...perhaps I should add an option to make the Numerical Sort perform in that way? But what would I call it...

Surely that is not a true Numerical Sort, rather it prioritises Alphabetical over Numerical...

Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 04:22:52 PM
"Arch Sort" 8-)
or
"Architectural Sort"
Title: Re: TabSort.lsp
Post by: alanjt on September 17, 2009, 04:31:23 PM
I'm not sure that I want to completely replace my Numerical Sort with one that would sort the tabs in that order though...perhaps I should add an option to make the Numerical Sort perform in that way? But what would I call it...

Surely that is not a true Numerical Sort, rather it prioritises Alphabetical over Numerical...


A10 should not precede A2 though.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 04:53:46 PM
"Arch Sort" 8-)
or
"Architectural Sort"

True, might consider it then  :-)

A10 should not precede A2 though.

It doesn't if I use my #Sort, but obviously does using Alpha.
Title: Re: TabSort.lsp
Post by: T.Willey on September 17, 2009, 05:09:31 PM
Maybe have the sort button pull up a little dialog box, where the user could type in the sort criteria.

/idea
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 05:25:40 PM
Maybe have the sort button pull up a little dialog box, where the user could type in the sort criteria.

/idea

Hmm... nice idea Tim, I could make the "Alpha" and "#Sort" buttons into one "Sort.." button - and make a dialog with a popup_list [?] containing "Alphabetical" "Numerical" "Architectural"... [ but then I would be one button short on the dialog and would have to think up another idea to add to it... :P ]
Title: Re: TabSort.lsp
Post by: T.Willey on September 17, 2009, 06:27:02 PM
Maybe have the sort button pull up a little dialog box, where the user could type in the sort criteria.

/idea

Hmm... nice idea Tim, I could make the "Alpha" and "#Sort" buttons into one "Sort.." button - and make a dialog with a popup_list [?] containing "Alphabetical" "Numerical" "Architectural"... [ but then I would be one button short on the dialog and would have to think up another idea to add to it... :P ]

Or just redesign the button organization.  But that is just the looks... what matters is the code behind the looks.   :wink:
Title: Re: TabSort.lsp
Post by: VovKa on September 17, 2009, 06:59:34 PM
keep it up, Lee

p.s.
it's much easier to write "action_tile" code with the help of vl-prin1-to-string
Code: [Select]
(action_tile
  "tabs"
  (vl-prin1-to-string
    (quote
      (progn
(setq #st (getvar "DATE")
      ptr $value
)
(if (and (eq dbptr $value) (< (abs (read (rtos (- #en #st) 2 10))) 0.0000011667))
  (progn (Makelst "tabs" (setq dclst (tab_rename (atoi ptr) dclst)))
(setq dbptr nil)
(set_tile "tabs" ptr)
  )
  (setq #en   (getvar "DATE")
dbptr $value
  )
)
      )
    )
  )
)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 07:21:09 PM
Just been looking into that "Architectural Sort", as Alan proposed...

Sounds to me like they need to be sorted first by any alpha that comes before a number, then each different alpha "prefix" needs to be sorted by the numerical element, then by the next alpha element.

So if I understand it correctly:

Code: [Select]
("AB12F" "AB07E" "AA24D" "ABC1P" "AB07D" "BA1")

Goes to:

Code: [Select]
("AA24D" "AB07D" "AB07E" "AB12F" "ABC1P" "BA1")

I thought it might help to break each string into corresponding Alphas and Numbers, so that each could be sorted by each section:

Code: [Select]
(defun StrBrk (str / x slst nLst rLst aLst)
  
  (setq slst (vl-string->list str))
  
  (while (setq x (car slst))
    (setq slst (cdr slst))
    (cond (  (< 47 x 58)
             (setq nLst (cons x nLst))
             (setq rLst (cons (reverse aLst) rLst) aLst nil))
          (t (setq aLst (cons x aLst))
             (setq rLst (cons (reverse nLst) rLst) nLst nil))))
  
  (mapcar 'vl-list->string
    (vl-remove nil
      (reverse
        (cons (reverse aLst)
          (cons (reverse nLst) rLst))))))


Hence:

Code: [Select]
(StrBrk "NJ2346NJ2B6BB2B6B2U")
("NJ" "2346" "NJ" "2" "B" "6" "BB" "2" "B" "6" "B" "2" "U")

So I propose this:

Code: [Select]
(defun StrBrk (str / x slst nLst rLst aLst)
  
  (setq slst (vl-string->list str))
  
  (while (setq x (car slst))
    (setq slst (cdr slst))
    (cond (  (< 47 x 58)
             (setq nLst (cons x nLst))
             (setq rLst (cons (reverse aLst) rLst) aLst nil))
          (t (setq aLst (cons x aLst))
             (setq rLst (cons (reverse nLst) rLst) nLst nil))))
  
  (mapcar 'vl-list->string
    (vl-remove nil
      (reverse
        (cons (reverse aLst)
          (cons (reverse nLst) rLst))))))

(defun ArchSort (lst)

    (vl-sort lst
      (function
        (lambda (a b / a b)
          (setq a (StrBrk a) b (StrBrk b))

          (while (and a b (or (not
                                (apply '=
                                  (mapcar 'type
                                    (mapcar 'read
                                      (mapcar 'car (list a b))))))
                              (apply '= (mapcar 'car (list a b)))))
            (setq a (cdr a) b (cdr b)))

          (cond (  (not a) (car b))
                (  (not b) (car a))
                (  (apply 'and
                     (mapcar 'numberp
                       (mapcar 'read
                         (mapcar 'car (list a b)))))
                   (< (read (car a)) (read (car b))))
                (t (< (car a) (car b))))))))

Could someone verify that it is sorting the elements correctly... or whether I have just trundled down the wrong route with it...   :roll:

Thanks,

Lee
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 07:22:21 PM
keep it up, Lee

p.s.
it's much easier to write "action_tile" code with the help of vl-prin1-to-string

Ahh, nice idea Vovka - I'll remember that one for next time  :-)

Will incorporate it into the next version to make it more readable for others  :-)
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 07:32:01 PM
More buttons?
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 07:34:03 PM
Yeah, I was thinking that - but I didn't want to clutter the dialog with loadsa buttons, I may have one "Sort" button, and a radio_row for the sort options.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 17, 2009, 07:46:43 PM
Actually, this is 3x faster .... what was I thinking all those mapcar's....    :ugly:


Code: [Select]
;; ArchSort by Lee McDonnell  ~  18/09/2009

(defun StrBrk (str / x slst nLst rLst aLst)
 
  (setq slst (vl-string->list str))
 
  (while (setq x (car slst))
    (setq slst (cdr slst))
    (cond (  (< 47 x 58)
             (setq nLst (cons x nLst))
             (setq rLst (cons (reverse aLst) rLst) aLst nil))
          (t (setq aLst (cons x aLst))
             (setq rLst (cons (reverse nLst) rLst) nLst nil))))
 
  (mapcar 'vl-list->string
    (vl-remove nil
      (reverse
        (cons (reverse aLst)
          (cons (reverse nLst) rLst))))))




(defun ArchSort2 (lst)

    (vl-sort lst
      (function
        (lambda (a b / a b)
          (setq a (StrBrk a) b (StrBrk b))

          (while (and a b (or (/= (type (read (car a)))
                                  (type (read (car b))))
                              (= (car a) (car b))))
            (setq a (cdr a) b (cdr b)))

          (cond (  (not a) (car b))
                (  (not b) (car a))
                (  (and (numberp (car a))
                        (numberp (car b)))
                   (< (read (car a)) (read (car b))))
                (t (< (car a) (car b))))))))

Code: [Select]
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (ARCHSORT2 LST).....1622 / 3.39 <fastest>
    (ARCHSORT LST)......5491 / 1.00 <slowest>
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 08:04:33 PM
Not quite there.
(ArchSort2 '("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12"))
("A-1" "A-11" "A-2" "AC12" "AC3" "E-1" "E-2" "M10" "M-4")
Title: Re: TabSort.lsp
Post by: CAB on September 17, 2009, 08:14:28 PM
Oh,  I just remembered that some Architects use decimal numbers.
(ArchSort2 '("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12" "A-1.2"))
("A-1.2" "A-1" "A-11" "A-2" "AC12" "AC3" "E-1" "E-2" "M10" "M-4")
should be
("A-1" "A-1.2" "A-2" "A-11" "AC3" "AC12" "E-1" "E-2" "M-4" "M10")
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 06:27:56 AM
This should now cope with the decimals quite nicely  :-)

Code: [Select]
;; ArchSort by Lee McDonnell  ~  18/09/2009

(defun StrBrk (str / x slst nLst rLst aLst)
 
  (setq slst (vl-string->list str))
 
  (while (setq x (car slst))
    (setq slst (cdr slst))
    (cond (  (and nLst (= 46 x))
             (setq nLst (cons x nLst)))
          (  (< 47 x 58)
             (setq nLst (cons x nLst))
             (setq rLst (cons (reverse aLst) rLst) aLst nil))
          (t (setq aLst (cons x aLst))
             (setq rLst (cons (reverse nLst) rLst) nLst nil))))
 
  (mapcar 'vl-list->string
    (vl-remove nil
      (reverse
        (cons (reverse aLst)
          (cons (reverse nLst) rLst))))))


(defun ArchSort2 (lst)

    (vl-sort lst
      (function
        (lambda (a b / a b t1 t2)
          (setq a (StrBrk a) b (StrBrk b))

          (while (and a b (or (not (or (= 'SYM (setq t1 (type (read (car a))))
                                               (setq t2 (type (read (car b)))))
                                       (and (vl-position t1 '(INT REAL))
                                            (vl-position t2 '(INT REAL)))))
                              (= (car a) (car b))))
            (setq a (cdr a) b (cdr b)))

          (cond (  (not a) (car b))
                (  (not b) (car a))
                (  (and (numberp (read (car a)))
                        (numberp (read (car b))))
                   (< (read (car a)) (read (car b))))
                (t (< (car a) (car b))))))))

Code: [Select]
(ArchSort2 '("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12" "A-1.2"))
("A-1" "A-1.2" "A-2" "A-11" "AC3" "AC12" "E-1" "E-2" "M10" "M-4")
Title: Re: TabSort.lsp
Post by: gile on September 18, 2009, 06:55:20 AM
Hi,

Code: [Select]
(defun archSort (lst / NumSuff)
  (defun NumSuff (str / slst loop x num dot)
    (setq slst (reverse (vl-string->list str))
          loop T
    )
    (while loop
      (setq x (car slst))
      (cond
        ((< 47 x 58)
         (setq num  (cons x num)
               slst (cdr slst)
         )
        )
        ((and (= x 46) (not dot))
         (setq num  (cons x num)
               slst (cdr slst)
               dot  T
         )
        )
        (T (setq loop nil))
      )
    )
    (cons (vl-list->string (reverse slst)) (read (vl-list->string num)))
  )

  (mapcar
    (function
      (lambda (x)
        (nth x lst)
      )
    )
    (vl-sort-i (mapcar 'NumSuff lst)
               (function
                 (lambda (x1 x2)
                   (if (= (car x1) (car x2))
                     (< (cdr x1) (cdr x2))
                     (< (car x1) (car x2))
                   )
                 )
               )
    )
  )
)

<EDIT> : a little benchmark

Quote
_$ (setq lst '("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12" "A-1.2"))
("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12" "A-1.2")
_$ (BENCHMARK '((ArchSort2_Lee lst) (ArchSort_gile lst)))
Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s):

    (ARCHSORT_GILE LST)......1578 / 6.46 <fastest>
    (ARCHSORT2_LEE LST).....10188 / 1.00 <slowest>
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 07:10:22 AM
Faster, but perhaps not conclusive:   :evil:
 
Code: [Select]
(archsort2 '("A-1A" "A-10A" "A-2B" "A-10B"))
("A-1A" "A-2B" "A-10A" "A-10B")

 (archsort '("A-1A" "A-10A" "A-2B" "A-10B"))
("A-10A" "A-10B" "A-1A" "A-2B")

<EDIT>  Nice code btw :P

Title: Re: TabSort.lsp
Post by: gile on September 18, 2009, 07:19:08 AM
Sorry, but I didn't read nothing about these kind of alphanumerical suffixes.
Thought there're only numerical suffixes.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 07:45:14 AM
Tbh Gile, I've never come across this kind of sorting - I'm just following the link that CAB provided  :-)

I like your idea of using the vl-sort-i in place of vl-sort, meaning that you can use your sub-function on the list before sorting it, instead of inside the sort function (as in mine) - probably a much quicker way to do it.  8-)
Title: Re: TabSort.lsp
Post by: gile on September 18, 2009, 08:44:00 AM
This one seems to work as you want

<EDIT>: the 'read' were misplaced

Code: [Select]
(defun archSort_gile2 (lst / SplitStr lst)
  (defun SplitStr (str / num-sub str-sub lst)

    (defun str-sub (char lst)
      (if lst
        (if (< 47 (car lst) 58)
          (cons char (num-sub (chr (car lst)) (cdr lst)))
          (str-sub (strcat char (chr (car lst))) (cdr lst))
        )
        (list char)
      )
    )

    (defun num-sub (char lst / tmp)
      (cond
        ((null lst) (list char))
        ((= 46 (car lst))
         (if (and (cadr lst)
                  (numberp
                    (read (setq tmp (strcat char "." (chr (cadr lst)))))
                  )
             )
           (num-sub tmp (cddr lst))
           (cons char (str-sub (chr (car lst)) (cdr lst)))
         )
        )
        ((< 47 (car lst) 58)
         (num-sub (strcat char (chr (car lst))) (cdr lst))
        )
        (T (cons char (str-sub (chr (car lst)) (cdr lst))))
      )
    )

    (setq lst (vl-string->list str))
    (if (< 47 (car lst) 58)
      (num-sub (chr (car lst)) (cdr lst))
      (str-sub (chr (car lst)) (cdr lst))
    )
  )

  (mapcar
    (function
      (lambda (x)
        (nth x lst)
      )
    )
    (vl-sort-i
      (mapcar 'SplitStr lst)
      (function
        (lambda (x1 x2 / s1 s2 n1 n2)
          (while (= (setq s1 (car x1)) (setq s2 (car x2)))
            (setq x1 (cdr x1)
                  x2 (cdr x2)
            )
          )
          (if (and (numberp (setq n1 (read s1))) (numberp (setq n2 (read s2))))
            (< n1 n2)
            (< s1 s2)
          )
        )
      )
    )
  )
)

Quote
_$ (BENCHMARK '((ArchSort2_Lee lst) (ArchSort_gile2 lst)))
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):

    (ARCHSORT_GILE2 LST).....1140 / 4.43 <fastest>
    (ARCHSORT2_LEE LST)......5047 / 1.00 <slowest>


Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 09:09:23 AM
Nice Gile,

I'm catching up, but you're still quicker  :oops:

Code: [Select]
(defun ArchSort3_lee (lst / StrBrk)

  (defun StrBrk (Str / x sLst nLst rLst aLst)
 
  (setq sLst (vl-string->list Str))
 
  (while (setq x (car sLst))
    (setq sLst (cdr sLst))
    (cond (  (and nLst (= 46 x))
             (setq nLst (cons x nLst)))
          (  (< 47 x 58)
             (setq nLst (cons x nLst))
             (setq rLst (cons (reverse aLst) rLst) aLst nil))
          (t (setq aLst (cons x aLst))
             (setq rLst (cons (reverse nLst) rLst) nLst nil))))
 
  (mapcar 'vl-list->string
    (reverse
      (vl-remove nil
        (cons (reverse aLst)
          (cons (reverse nLst) rLst))))))

  (mapcar
    (function
      (lambda (x)
        (nth x lst)))

    (vl-sort-i (mapcar 'StrBrk lst)
      (function
        (lambda (a b / a b t1 t2)
         
          (while (and a b (or (not (or (= 'SYM (setq t1 (type (read (car a))))
                                               (setq t2 (type (read (car b)))))
                                       (and (vl-position t1 '(INT REAL))
                                            (vl-position t2 '(INT REAL)))))
                              (= (car a) (car b))))
            (setq a (cdr a) b (cdr b)))

          (cond (  (not a) (car b))
                (  (not b) (car a))
                (  (and (numberp (read (car a)))
                        (numberp (read (car b))))
                   (< (read (car a)) (read (car b))))
                (t (< (car a) (car b)))))))))

Code: [Select]
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):

    (ARCHSORT_GILE2 LST).....1045 / 1.97 <fastest>
    (ARCHSORT3_LEE LST)......2059 / 1.00 <slowest>
Title: Re: TabSort.lsp
Post by: gile on September 18, 2009, 09:25:11 AM
I made a little correction in archSort_gile2: the read statements were in SplitStr and an error occured when comparing a string and a number.
After correction the speed difference with your last code is smaller.

So, I try to optimize the SplitList sub (avoiding recursive process) in archSort_gile3:

Code: [Select]
(defun archSort_gile3 (lst / SplitStr lst)
  (defun SplitStr (str / lst test rslt num tmp)
    (setq lst  (vl-string->list str)
          test (chr (car lst))
    )
    (if (< 47 (car lst) 58)
      (setq num T)
    )
    (while (setq lst (cdr lst))
      (if num
        (cond
          ((= 46 (car lst))
           (if (and (cadr lst)
                    (setq tmp (strcat test "." (chr (cadr lst))))
                    (numberp (read tmp))
               )
             (setq test tmp
                   lst  (cdr lst)
             )
             (setq rslt (cons test rslt)
                   test "."
                   num  nil
             )
           )
          )
          ((< 47 (car lst) 58)
           (setq test (strcat test (chr (car lst))))
          )
          (T
           (setq rslt (cons test rslt)
                 test (chr (car lst))
                 num  nil
           )
          )
        )
        (if (< 47 (car lst) 58)
          (setq rslt (cons test rslt)
                test (chr (car lst))
                num  T
          )
          (setq test (strcat test (chr (car lst))))
        )
      )
    )
    (setq rslt (cons test rslt))
    (reverse rslt)
  )

  (mapcar
    (function
      (lambda (x)
        (nth x lst)
      )
    )
    (vl-sort-i
      (mapcar 'SplitStr lst)
      (function
        (lambda (x1 x2 / s1 s2)
          (while (= (setq s1 (car x1)) (setq s2 (car x2)))
            (setq x1 (cdr x1)
                  x2 (cdr x2)
            )
          )
          (if (and (numberp (read s1)) (numberp (read s2)))
            (< (read s1) (read s2))
            (< s1 s2)
          )
        )
      )
    )
  )
)

Quote
_$ (BENCHMARK '((ArchSort3_Lee lst) (ArchSort_gile2 lst) (ArchSort_gile3 lst)))
Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s):

    (ARCHSORT_GILE3 LST).....1296 / 1.25 <fastest>
    (ARCHSORT_GILE2 LST).....1453 / 1.12
    (ARCHSORT3_LEE LST)......1625 / 1.00 <slowest>
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 09:48:11 AM
Gile I get this from your latest entry  :-(

Quote
(ArchSort_gile3 '("E-2" "M-4" "M10" "A-11" "A-2" "A-1" "E-1" "AC3" "AC12" "A-1.2"))
; error: bad argument type: stringp 1
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 09:56:42 AM
Had superfluous code:

Code: [Select]
(defun ArchSort_lee6 (lst / StrBrk)

  (defun StrBrk (Str / x sLst nLst rLst aLst)
 
  (setq sLst (vl-string->list Str) aLst "" nLst "")
 
  (while (setq x (car sLst))
    (setq sLst (cdr sLst))
    (cond (  (and  nLst (= 46 x))
             (setq nLst (strcat nLst (chr x))))
          (  (< 47 x 58)
             (setq nLst (strcat nLst (chr x)))
             (setq rLst (cons aLst rLst) aLst ""))
          (t (setq aLst (strcat aLst (chr x)))
             (setq rLst (cons (cond ((read nLst)) ("")) rLst) nLst ""))))
 
  (reverse
    (vl-remove ""
      (cons aLst
        (cons (cond ((read nLst)) ("")) rLst)))))

  (mapcar
    (function
      (lambda (x)
        (nth x lst)))

    (vl-sort-i (mapcar 'StrBrk lst)
      (function
        (lambda (a b / a b x1 x2)
         
          (while (and (setq x1 (car a))                     
                      (setq x2 (car b))
                      (or (= x1 x2)
                          (not (or (= 'STR (type x1) (type x2))
                                   (and (numberp x1) (numberp x2))))))                     
            (setq a (cdr a) b (cdr b)))

          (< (car a) (car b)))))))

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

    (ARCHSORT_GILE2 LST).....1232 / 1.25 <fastest>
    (ARCHSORT_LEE6 LST)......1544 / 1.00 <slowest>

<EDIT>  I spoke too soon... edited, as old code fell down with :  '("A32B" "34C")
Title: Re: TabSort.lsp
Post by: gile on September 18, 2009, 10:26:53 AM
I forgot to remove a (read ...) in SplitStr.
I edited the code.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 10:44:40 AM
You're still quicker  :evil:

I wasn't sure what would be better - having the "read" in the vl-sort-i, or in the function to break the String into Numbers and Strings..  :|

Title: Re: TabSort.lsp
Post by: CHulse on September 18, 2009, 03:38:14 PM
Lee, Awesome tool - thanks.

Have you considered adding the ability to remove/replace an existing prefix/sufix (in addition to the add feature you have)?
Title: Re: TabSort.lsp
Post by: Hugo on September 18, 2009, 04:06:26 PM
Hallo Lee
Bekomme folgende Meldung

** DCL File Could not be Written **

Danke
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 04:20:18 PM
Lee, Awesome tool - thanks.

Have you considered adding the ability to remove/replace an existing prefix/sufix (in addition to the add feature you have)?

Thanks Cary   8-)

I hadn't considered it - I suppose it would be part of the Rename function, but I am not certain as to how the user would specify what he/she wanted to remove (i.e. how would I recognise a prefix...)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 04:24:57 PM
Hallo Lee
Bekomme folgende Meldung

** DCL File Could not be Written **

Danke

Hugo,

The DCL file is written to the same location as the ACAD.PAT file - [using the sub-function at the bottom of the LISP], so my guess is that it can't find this file.

What do you get if you type this at the command line:

Code: [Select]
(findfile "ACAD.PAT")



Die DCL-Datei wird an den gleichen Ort wie die Datei geschrieben ACAD.PAT - [mit dem Sub-Funktion am Ende des LISP], so meine Vermutung ist, dass es diese Datei nicht finden kann.

Was bekommt man, wenn man diese Art in der Befehlszeile:

Code: [Select]
(findfile "ACAD.PAT")
Title: Re: TabSort.lsp
Post by: CHulse on September 18, 2009, 04:39:53 PM
Lee, Awesome tool - thanks.

Have you considered adding the ability to remove/replace an existing prefix/sufix (in addition to the add feature you have)?

Thanks Cary   8-)

I hadn't considered it - I suppose it would be part of the Rename function, but I am not certain as to how the user would specify what he/she wanted to remove (i.e. how would I recognise a prefix...)


Well, I don't know. But the example I have is is this:

TP1
TP2
TP3
TP4

I need to change the "TP" to "L-" for example.

Not sure how it might work though.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 18, 2009, 04:59:03 PM
Lee, Awesome tool - thanks.

Have you considered adding the ability to remove/replace an existing prefix/sufix (in addition to the add feature you have)?

Thanks Cary   8-)

I hadn't considered it - I suppose it would be part of the Rename function, but I am not certain as to how the user would specify what he/she wanted to remove (i.e. how would I recognise a prefix...)


Well, I don't know. But the example I have is is this:

TP1
TP2
TP3
TP4

I need to change the "TP" to "L-" for example.

Not sure how it might work though.

OK, I'll have a think and see what I can come up with   :-)
Title: Re: TabSort.lsp
Post by: Aerdvark on September 19, 2009, 01:14:02 AM
Beware of remaming multiple tabs the same name ie.:
"layout01" "layout02" "layout03" minus a suffix of 2 letters will give you 3 x "layout".
Title: Re: TabSort.lsp
Post by: Hugo on September 19, 2009, 02:29:58 AM
Hallo Lee

Sorry ivh habe es auf zwcad getestet.
Auf Autocad läuft es super.
Danke für die rasche Antwort
 :-) :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 19, 2009, 07:31:01 AM
Beware of remaming multiple tabs the same name ie.:
"layout01" "layout02" "layout03" minus a suffix of 2 letters will give you 3 x "layout".


Yes - duplicate layout tabs have to be checked for in many of the other functions too  ;-)

Thanks for the warning though Marco  :-)

With this, I may just make a "Find & Replace" button, to find a textstring within a tab name, and replace it with something else  :-)

Hallo Lee

Sorry ivh habe es auf zwcad getestet.
Auf Autocad läuft es super.
Danke für die rasche Antwort
 :-) :-)

Glad we cleared that up :-)

Thanks Hugo  8-)

Title: Re: TabSort.lsp
Post by: Lee Mac on September 19, 2009, 08:37:46 AM
What are your thoughts on this as an addition?

Title: Re: TabSort.lsp
Post by: Lee Mac on September 19, 2009, 01:48:03 PM
I have updated the first post to Version 1.6 to include the Architectural Sort  8-)
Title: Re: TabSort.lsp
Post by: CAB on September 19, 2009, 03:12:17 PM
Thanks for all you hard work Lee.

When you select more than one tab & go to Prefix, unchecking the "Apply to All Tabs" does not
prevent renaming all the tabs.

Also crashed the routine when I copied a tab, added a prefix, reset (which also revoved the copied tab from the list but it was still in the DWG)
then I added the prefix again. When I hit DONE.

Crashed here at line 333:
Code: [Select]
               (foreach tab lst
                  (vla-put-TabOrder tab
                    (1+ (vl-position
                          (strcase (vla-get-Name tab)) dclst))))))
                         

because the name was not in the dclst & returned nil
Title: Re: TabSort.lsp
Post by: Lee Mac on September 19, 2009, 06:09:53 PM
Thanks for all you hard work Lee.

When you select more than one tab & go to Prefix, unchecking the "Apply to All Tabs" does not
prevent renaming all the tabs.

Also crashed the routine when I copied a tab, added a prefix, reset (which also revoved the copied tab from the list but it was still in the DWG)
then I added the prefix again. When I hit DONE.

Crashed here at line 333:
Code: [Select]
               (foreach tab lst
                  (vla-put-TabOrder tab
                    (1+ (vl-position
                          (strcase (vla-get-Name tab)) dclst))))))
                         

because the name was not in the dclst & returned nil


Many thanks Alan for your feedback.

There have been a lot of changes to the code in a short span of time, and I haven't had a chance to fully put the routine through its paces - no doubt I have overlooked something along the way.

I shall look into the errors that you have reported  :-)

Thanks once again,

Lee

Title: Re: TabSort.lsp
Post by: Lee Mac on September 19, 2009, 07:38:16 PM
Alan, I have updated the first post with Version 1.6.1, which should hopefully fix the bugs you reported.  8-)

<EDIT> left a small sub-function straggling - code updated.
Title: Re: TabSort.lsp
Post by: CAB on September 19, 2009, 09:21:56 PM
Thanks, I'll give it a try later tonight or tomorrow.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 20, 2009, 10:31:43 AM
First post updated to Version 1.7 to include the features as listed  ;-)
Title: Re: TabSort.lsp
Post by: gile on September 20, 2009, 02:37:57 PM
Hi Lee,

Back to ArchSort, it seems there's something wrong with the routine in Version 1.7

(setq lst '("A1.03.5" "A1.20.25" "A1.03.15" "A1.12.4" "A1.01.5" "A1.0.5"))

(archsort lst)
returns:
("A1.0.5" "A1.01.5" "A1.12.4" "A1.03.15" "A1.20.25" "A1.03.5")
instead of:
("A1.0.5" "A1.01.5" "A1.03.15" "A1.03.5" "A1.12.4" "A1.20.25")

I think it's due to the StrBrk routine

Here's one which seems to work.

Code: [Select]
(defun SplitStr (str / lst test rslt num tmp)
  (setq lst  (vl-string->list str)
test (chr (car lst))
  )
  (if (< 47 (car lst) 58)
    (setq num T)
  )
  (while (setq lst (cdr lst))
    (if num
      (cond
((= 46 (car lst))
          (if (and (cadr lst)
                   (setq tmp (strcat "0" "." (chr (cadr lst))))
                   (numberp (read tmp))
              )
            (setq rslt (cons (read test) rslt)
                  test tmp
                  lst  (cdr lst)
            )
            (setq rslt (cons (read test) rslt)
                  test "."
                  num  nil
            )
          )
        )
((< 47 (car lst) 58)
(setq test (strcat test (chr (car lst))))
)
(T
(setq rslt (cons (read test) rslt)
       test (chr (car lst))
       num  nil
)
)
      )
      (if (< 47 (car lst) 58)
(setq rslt (cons test rslt)
      test (chr (car lst))
      num  T
)
(setq test (strcat test (chr (car lst))))
      )
    )
  )
  (if num
    (setq rslt (cons (read test) rslt))
    (setq rslt (cons test rslt))
  )
  (reverse rslt)
)

(defun ArchSort (lst / comparable)
  (defun comparable (e1 e2)
    (or (and (numberp e1) (numberp e2))
        (= 'STR (type e1) (type e2))
        (not e1)
        (not e2)
    )
  )
  (mapcar
    (function
      (lambda (x)
        (nth x lst)
      )
    )
    (vl-sort-i
      (mapcar 'SplitStr lst)
      (function
        (lambda (x1 x2 / n1 n2 comp)
          (while
            (and
              (setq comp (comparable (setq n1 (car x1)) (setq n2 (car x2))))
              (= n1 n2)
            )
             (setq x1 (cdr x1)
                   x2 (cdr x2)
             )
          )
          (if comp
            (< n1 n2)
            (numberp n1)
          )
        )
      )
    )
  )
)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 20, 2009, 04:40:13 PM
Nice Gile - I hadn't accounted for the multiple decimals, with my previous routine:

Code: [Select]
(StrBrk "A1.2.3")  Returns:  ("A" 1)

As 1.2.3 will return nil upon reading.

Whereas yours:

Code: [Select]
(SplitStr "A1.2.3") Returns: ("A" 1 0.2 0.3)

Which is much more helpful for sorting  8-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 20, 2009, 05:09:31 PM
Gile I have Updated the first post with Version 1.7.1 ~ which includes your version of the Archsort function (with credit given  ;-) )

I have also modified your SplitStr function to only display numbers, for use with my NumSort function  :wink:

Thanks for all your help with this.  :-)
Title: Re: TabSort.lsp
Post by: CAB on September 20, 2009, 06:08:45 PM
OK where is the HELP button to explain all this?  :evil:
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 05:24:43 AM
OK where is the HELP button to explain all this?  :evil:

Hehe good point  - but tbh, I didn't really want a help button... I wanted to keep the number of buttons to a minimum so as not to clutter it too much... I think it is all pretty self explanatory really :P
Title: Re: TabSort.lsp
Post by: CAB on September 21, 2009, 09:42:54 AM
True but some users will still need some hand holding. :)

Here is an experiment using an almost hidden button which is accessed via the H key.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 10:30:56 AM
Nice idea!

On my screen, the button shows as just a small "bar", is this the same on yours? But this is not very noticeable, unless you know where to look  ;-)

I also like the way that you have incorporated the Dialog title as a key - makes it easier to remember when you notch it up a version  8-)

I think I will include this feature - help if you need it, but non-obtrusive for those who know what they are doing  :-)
Title: Re: TabSort.lsp
Post by: CAB on September 21, 2009, 12:50:12 PM
Glad you like it. Yes a small bar which you can click on too if you knew about it. :)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 12:50:31 PM
I have updated the first post to include Version 1.8, my thanks to CAB for his idea for the help button  8-)
Title: Re: TabSort.lsp
Post by: alanjt on September 21, 2009, 02:32:30 PM
Talk about 'out of control'. LoL
Very nice Lee.
Title: Re: TabSort.lsp
Post by: alanjt on September 21, 2009, 03:29:55 PM
Received an error when I tried to rename tab.

Code: [Select]
Command:
TABSORT Backtrace:
[0.93] (VL-BT)
[1.89] (*ERROR* "bad argument type: numberp: -")
[2.84] (_call-err-hook #<SUBR @1e913d48 *ERROR*> "bad argument type: numberp:
-")
[3.78] (sys-error "bad argument type: numberp: -")
:ERROR-BREAK.73 "bad argument type: numberp: -"
[4.70] (ABS -)
[5.65] (#<SUBR @1e44458c -lambda-> "tabs" "1" "" 4 75 14)
[6.56] (#<SUBR @173399ec -application-envelope->)
:ENTRY-NAMESPACE.53 (:ENTRY-NAMESPACE)
[7.50] (#<SUBR @17339a14 -unwind-protect->)
[8.47] (_lisplet-apply #<Document-LISPLET> #<SUBR @173399ec
-application-envelope-> nil nil)
[9.39] (_lisplet-app-apply #<Document-LISPLET> #<SUBR @1e44458c -lambda->
("tabs" "1" "" 4 75 14))
[10.32] (dcl-call-back ("tabs" "1" "" 4 75 14) T)
:DCL-ACTION.26 (((:DCL-ACTION "tabsort" "tabs" 4)))
[11.23] (START_DIALOG)
[12.19] (C:TABSORT)
[13.15] (#<SUBR @1e444550 -rts_top->)
[14.12] (#<SUBR @1733435c veval-str-body> "(C:TABSORT)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

** Error: bad argument type: numberp: - **
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 07:06:37 PM
Thanks Alan  8-)

I can't quite follow the backtrace too well - when exactly did it crash, and what did you try to rename the tab to (if you got that far)?
Title: Re: TabSort.lsp
Post by: CAB on September 21, 2009, 07:16:45 PM
My guess would be line 186
Code: [Select]
(< (abs (read (rtos (- #en #st) 2 10))) 0.0000011667))Maybe the read returned the minus sign and no number to evaluate.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 07:27:28 PM
Good point CAB - I notice the ABS in the backtrace and I believe that is the only line that uses it.

Did AJ maybe double click too fast  :evil:
Title: Re: TabSort.lsp
Post by: alanjt on September 21, 2009, 08:32:33 PM
Thanks Alan  8-)

I can't quite follow the backtrace too well - when exactly did it crash, and what did you try to rename the tab to (if you got that far)?
I couldn't get past the double-click.
Title: Re: TabSort.lsp
Post by: alanjt on September 21, 2009, 08:33:15 PM
Good point CAB - I notice the ABS in the backtrace and I believe that is the only line that uses it.

Did AJ maybe double click too fast  :evil:
LoL
I'm fast, but not that fast. I tried it several times, just to make sure.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 21, 2009, 08:41:40 PM
I think CAB is correct about the read statement not returning a valid number - but I cannot see why it is failing...

Just out of curiosity, try this at the command line... :P

Code: [Select]
(abs (read (rtos -1.01887e-006 2 10)))
Title: Re: TabSort.lsp
Post by: CAB on September 21, 2009, 09:19:54 PM
I have not been able to reproduce the error.

BTW Lee, The = is causing the DCL not to fire the first time when it is created
Code: [Select]
((<[color=red]=[/color] (setq dcTag (load_dialog fname)) 0)should be
Code: [Select]
((< (setq dcTag (load_dialog fname)) 0)
Title: Re: TabSort.lsp
Post by: alanjt on September 21, 2009, 09:23:20 PM
I have not been able to reproduce the error.
Odd, I'll have to try it when I can get back on the PC (wife is using it). Perhaps it was an isolated incident. I did only run it one session; should have restarted AutoCAD.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 22, 2009, 07:37:32 AM
I have not been able to reproduce the error.

BTW Lee, The = is causing the DCL not to fire the first time when it is created
Code: [Select]
((<[color=red]=[/color] (setq dcTag (load_dialog fname)) 0)should be
Code: [Select]
((< (setq dcTag (load_dialog fname)) 0)

Thats funny - the equals makes no difference to mine  :? - but I shall change it anyway.

I have not been able to reproduce the error.
Odd, I'll have to try it when I can get back on the PC (wife is using it). Perhaps it was an isolated incident. I did only run it one session; should have restarted AutoCAD.

I couldn't reproduce the error either, unless your DATE sys var is somehow "corrupted", I can't think of any other explanation...  :-(
Title: Re: TabSort.lsp
Post by: alanjt on September 22, 2009, 08:32:01 AM
It's the dimzin variable. We use dimzin 12 to remove leading and trailing zeros. As a result, read returns only a '-' and abs freaks out.

I have not been able to reproduce the error.

BTW Lee, The = is causing the DCL not to fire the first time when it is created
Code: [Select]
((<[color=red]=[/color] (setq dcTag (load_dialog fname)) 0)should be
Code: [Select]
((< (setq dcTag (load_dialog fname)) 0)

Thats funny - the equals makes no difference to mine  :? - but I shall change it anyway.

I have not been able to reproduce the error.
Odd, I'll have to try it when I can get back on the PC (wife is using it). Perhaps it was an isolated incident. I did only run it one session; should have restarted AutoCAD.

I couldn't reproduce the error either, unless your DATE sys var is somehow "corrupted", I can't think of any other explanation...  :-(
Title: Re: TabSort.lsp
Post by: Lee Mac on September 22, 2009, 08:41:48 AM
Ahhh of couse!

Ok, then I suppose an easy fix would be to just set the DIMZIN to say 0, and reset it after program completion  ;-)
Title: Re: TabSort.lsp
Post by: alanjt on September 22, 2009, 08:53:46 AM
Ahhh of couse!

Ok, then I suppose an easy fix would be to just set the DIMZIN to say 0, and reset it after program completion  ;-)
It's an easy-to-squash bug.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 22, 2009, 09:01:59 AM
Bug Squashed  8-)

First post updated to Version 1.8.1 to include the bug fixes for the two Alans  :-)
Title: Re: TabSort.lsp
Post by: alanjt on September 22, 2009, 09:14:18 AM
Bug Squashed  8-)

First post updated to Version 1.8.1 to include the bug fixes for the two Alans  :-)
We're buggy people.  :-o :lol:
Title: Re: TabSort.lsp
Post by: CAB on September 22, 2009, 09:25:58 AM
I have not been able to reproduce the error.

BTW Lee, The = is causing the DCL not to fire the first time when it is created
Code: [Select]
((<[color=red]=[/color] (setq dcTag (load_dialog fname)) 0)should be
Code: [Select]
((< (setq dcTag (load_dialog fname)) 0)

Thats funny - the equals makes no difference to mine  :? - but I shall change it anyway.

Maybe it's ACAD2000 but the help says negative numbers signal failure so zero is returned on my system.
Title: Re: TabSort.lsp
Post by: Lee Mac on September 22, 2009, 09:33:50 AM
I have not been able to reproduce the error.

BTW Lee, The = is causing the DCL not to fire the first time when it is created
Code: [Select]
((<[color=red]=[/color] (setq dcTag (load_dialog fname)) 0)should be
Code: [Select]
((< (setq dcTag (load_dialog fname)) 0)

Thats funny - the equals makes no difference to mine  :? - but I shall change it anyway.

Maybe it's ACAD2000 but the help says negative numbers signal failure so zero is returned on my system.


True, but then zero is neither positive or negative - I just err'd on the wrong side thats all  :-)
Title: Re: TabSort.lsp
Post by: VovKa on September 23, 2009, 12:39:39 PM
1 delete all layouts
2 reset
3 done
4 error
Title: Re: TabSort.lsp
Post by: Lee Mac on September 23, 2009, 12:47:02 PM
Haha thanks VovKa you made my day  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 23, 2009, 01:02:57 PM
Code updated to accommodate the VovKa's Bug  ;-)
Title: Re: TabSort.lsp
Post by: CAB on September 23, 2009, 05:32:51 PM
While the Help DCL looks great I would change to ok_cancel button to on_only in you next revision.  8-)
Title: Re: TabSort.lsp
Post by: Lee Mac on September 23, 2009, 06:09:00 PM
While the Help DCL looks great I would change to ok_cancel button to on_only in you next revision.  8-)

Good point Alan, habit got the better of me on that one  :wink:
Title: Re: TabSort.lsp
Post by: CHulse on September 30, 2009, 09:14:56 AM
Lee,
I've finally had some time to play with your latest version and I must say, very nice. Thank You Sir!
Title: Re: TabSort.lsp
Post by: Lee Mac on September 30, 2009, 11:37:35 AM
Lee,
I've finally had some time to play with your latest version and I must say, very nice. Thank You Sir!

Your very welcome Cary  :-)
Title: Re: TabSort.lsp
Post by: bikerholic on October 02, 2009, 07:02:40 AM
hello lee

this tool is amazing   :-o

it works great and it is really usefull thanks a lot  8-)

i have test it a while so now i had some suggestions for improvement

1. if i select a group of layouts for getting them revers on their position in the list the completely list getting revers

2. if i copy a layout it becomes to the end of the list
so i think it will be better for getting a opinion to select where the copy shout find his place
for example right next to the original layout or to the end or top

3. why is this tool not a original acad one  :kewl:


bye bye björn :)

p.s. sorry about my horrible english but give a german guy a chance  :wink:
Title: Re: TabSort.lsp
Post by: Lee Mac on October 02, 2009, 07:10:28 AM
Hey björn,

Thanks for your comments :-)

Your English is pretty good - don't worry mate   8-)

The Reverse function has stayed the same since Version 1, when the user could only select one tab at a time, so perhaps it is time for me to upgrade that  :wink:

I'm not sure about the copy placement - perhaps it is more logical to place the tab below the original... what do others think about this?

Quote
3. why is this tool not a original acad one 

That could be said about so many of the great programs posted on here  :wink:


Thanks for your feedback and comments björn, much appreciated as always  :-)

Lee
Title: Re: TabSort.lsp
Post by: CAB on October 02, 2009, 08:42:32 AM
As for the New Copy of a layout, the end position is my logical choice. Hard to guess where each user wants it.
I suggest a hard coded variable the user could set for beginning of list/below original/end of list.

Regarding the Group selection, I for one think each operation should respond to this selection.
That is to say sort, reverse, etc should operate on the selected group. That said I'm not sure how
I would treat a non-continuous selection. What to do with the items in the middle of the group.

You've done a good job with the routine as it is Lee.
Title: Re: TabSort.lsp
Post by: Lee Mac on October 02, 2009, 09:42:11 AM
As for the New Copy of a layout, the end position is my logical choice. Hard to guess where each user wants it.
I suggest a hard coded variable the user could set for beginning of list/below original/end of list.

I would agree with you here Alan, although I think it is a lot of work to implement this, for very little gain (as there are many other tools included to move the copied layouts anyway).

Regarding the Group selection, I for one think each operation should respond to this selection.
That is to say sort, reverse, etc should operate on the selected group. That said I'm not sure how
I would treat a non-continuous selection. What to do with the items in the middle of the group.

I completely agree with you here - everything should be consistent.

You've done a good job with the routine as it is Lee.

Thanks Alan  8-)
Title: Re: TabSort.lsp
Post by: Lee Mac on October 02, 2009, 10:54:10 AM
I have updated the first post to Version 1.9, the Reverse Function will now only reverse Selected Tabs.

Enjoy :-)

Lee

Title: Re: TabSort.lsp
Post by: SteveK on October 05, 2009, 07:02:24 PM
Great program Lee, thanks.  :-)

It's hardly worth mentioning but once I click on one of the tabs the 'H' for help doesn't work. Who cares really, but just so you know.
Title: Re: TabSort.lsp
Post by: CAB on October 05, 2009, 11:59:38 PM
Here is an idea I was going to work on some time back, implement a Tab renaming routine to
maintain a list of "Short Tab Name" and "Long Tab Names".  To keep all the tabs in view in the
ACAD window I use abbreviated names. When I plot I would prefer long descriptive names for the
file names. To do this I was going to use x-data to save the list in the DWG. It occurred to me
this evening that that might be something to incorporate in the TabSort routine. One more button. :)
You already have the edit tab name.

Just pondering the possibilities. If you are like me, too busy to add another project at this time, ignore the suggestion. 8-)
Title: Re: TabSort.lsp
Post by: Lee Mac on October 06, 2009, 02:00:09 PM
Hi Guys,

Thanks for the comments and suggestions they are much appreciated.  :-)

>> Steve,

I would assume this occurs as the focus is no longer on the Main Dialog, but on the list_box, hence the "H" is not recognised, I suppose the only real way around this would be to add a help button...

>> Alan,

Thanks for the suggestion, I haven't heard of that idea before - but I'm not sure how "general" that would be... I wanted to keep the tool quite generic, and that sounds quick specific - but thanks anyway.



I've actually just started University now, and don't have a lot of time or access to the internet at home, so I can't spend as much time programming as I used to  :-(  But I shall still try to stay in touch as and when I can.  :-)

Thanks,

Lee
Title: Re: TabSort.lsp
Post by: Andrea on October 06, 2009, 04:00:25 PM
Lee,

this is just too Cool !! Nice one !

Idea concept = 10/10
Design concept = 10/10
easy to use = 10/10
code guru = 10/10

you got all my star !  congratulation !  ;-)


Need more idea ?:

a) incremental TAB?
b) String substitution? OOps...was on Find option  ;-)
c) TAB search? (we got strong drawings here)
d) UPERCASE/lowercase/Sentence string CAPs ?
e) Print TAB ?
f ) Delete all TAB ?


one thing...
In French release we have "Présentation1" as "Layout1"

Keep your Good work !
Title: Re: TabSort.lsp
Post by: Andrea on October 06, 2009, 04:19:21 PM
just for u...

 8-)

Title: Re: TabSort.lsp
Post by: CAB on October 06, 2009, 04:43:52 PM
Great program Lee, thanks.  :-)

It's hardly worth mentioning but once I click on one of the tabs the 'H' for help doesn't work. Who cares really, but just so you know.
Actually none of the mnemonics work WHILE the DCL focus is in the LIST Box. This is normal. select any button & the focus is changed and the mnemonics work again.
Title: Re: TabSort.lsp
Post by: GDF on October 06, 2009, 04:59:16 PM
Very nice Lee...
Title: Re: TabSort.lsp
Post by: Andrea on October 06, 2009, 05:08:00 PM
One more thing...

When the focus is on the ListBox and user press a Key...
It will find the First letter of each TAB name...
but, if you create a new TAB and than press a diffrent Key
this will change the order of the TAB list.

So I thing also a Help button will be better because this will interfer the search when pressing a key when
the focus is on the ListBox..

but...I love it !. thanks for sharing.
Title: Re: TabSort.lsp
Post by: bikerholic on October 09, 2009, 06:31:12 AM
but, if you create a new TAB and than press a diffrent Key
this will change the order of the TAB list.

hi andrea

its not a diffrent key so its all about the keys of the buttons with the underlined letter
so the temporary solution is after clicking the create button to click into the listbox and press your different key

and for the h key problem for help you can press the tab key and then the h key

bye and have a nice weekend björn :)


 
Title: Re: TabSort.lsp
Post by: bikerholic on October 09, 2009, 06:45:52 AM
I have updated the first post to Version 1.9, the Reverse Function will now only reverse Selected Tabs.
sensational thats nice thx *thumbs up*

I've actually just started University now, and don't have a lot of time or access to the internet at home, so I can't spend as much time programming as I used to  :-(  But I shall still try to stay in touch as and when I can.  :-)

I wish you much success and a good time see you next time  8-)

bye björn :)
Title: Re: TabSort.lsp
Post by: Lee Mac on October 09, 2009, 06:55:55 AM
Many thanks for all your replies guys, I haven't had much time to check the thread as I don't have internet at home at the moment.

>> Andrea,

Thanks for your suggestions, I may make the program language compatible when I get a minute or two  ;-)

I was thinking of including an increment for the prefix/suffix, but didn't get around to it in the end - but I like you idea of the Tab Search, that may come in useful :-)

Oh, and thanks for the icon  8-)

>> Bjorn,

You are correct in that the tile mnemonics mean that you can operate the program using the relevant keys (the underlined letters on the buttons), but this of course will only work when the focus is on the main dialog, and not on the list_box.  I didn't really want to clutter the dialog with more and more buttons, and so didn't want to include a specific help button...


Thanks for the comments guys, I'm glad you are enjoying the program.

Cheers,

Lee
Title: Re: TabSort.lsp
Post by: Lee Mac on October 09, 2009, 06:56:34 AM
I have updated the first post to Version 1.9, the Reverse Function will now only reverse Selected Tabs.
sensational thats nice thx *thumbs up*

I've actually just started University now, and don't have a lot of time or access to the internet at home, so I can't spend as much time programming as I used to  :-(  But I shall still try to stay in touch as and when I can.  :-)

I wish you much success and a good time see you next time  8-)

bye björn :)

Thanks Bjorn  8-)  This year is going to be pretty tough, but hopefully I can get through it OK.  :wink:
Title: Re: TabSort.lsp
Post by: CHulse on February 01, 2010, 08:15:32 AM
Lee,
Not that this tool isn't already a HUGE help and timesaver, because it really is. And thank you for it.

But, would it be possible to add the ability to remove or edit a prefix or sufix (not just add one)?

Thanks
Title: Re: TabSort.lsp
Post by: Lee Mac on February 01, 2010, 01:02:20 PM
Lee,
Not that this tool isn't already a HUGE help and timesaver, because it really is. And thank you for it.

But, would it be possible to add the ability to remove or edit a prefix or sufix (not just add one)?

Thanks

Hi Cary,

I think you asked something like this before - I added a 'Find & Replace' which should, I hope, accomplish what you wish  :-)

Lee
Title: Re: TabSort.lsp
Post by: CHulse on February 01, 2010, 01:13:20 PM
Lee,
Not that this tool isn't already a HUGE help and timesaver, because it really is. And thank you for it.

But, would it be possible to add the ability to remove or edit a prefix or sufix (not just add one)?

Thanks

Hi Cary,

I think you asked something like this before - I added a 'Find & Replace' which should, I hope, accomplish what you wish  :-)

Lee

Ooh - you're right, I forgot that  :oops:
Sorry
Title: Re: TabSort.lsp
Post by: Lee Mac on February 01, 2010, 01:15:21 PM
Lee,
Not that this tool isn't already a HUGE help and timesaver, because it really is. And thank you for it.

But, would it be possible to add the ability to remove or edit a prefix or sufix (not just add one)?

Thanks

Hi Cary,

I think you asked something like this before - I added a 'Find & Replace' which should, I hope, accomplish what you wish  :-)

Lee

Ooh - you're right, I forgot that  :oops:
Sorry

Not a problem :-)  I'm glad that you find the program of use  :-)
Title: Re: TabSort.lsp
Post by: VVA on July 22, 2010, 11:25:58 AM
Hi Lee Mac. Thanks again for the excellent work. Found another small bug.
Description:
1. We have a layout named "Layuot1"
2. Use the "Copy" to create two copies of the layout
3. We have layouts with the names "Layout1" "Layout1 (2)" "Layout1 (2) (2)"
4. Now press "Search". In the field "Find what" is entered (2), the field "Replace whith" left blank.
5. After clicking "Replace All" get an error
** Error: Automation Error. Invalid input **
(Trying to assign multiple worksheets the same name)
Title: Re: TabSort.lsp
Post by: Lee Mac on July 22, 2010, 02:25:52 PM
Thanks VVA, I'll look into it  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on July 22, 2010, 03:22:11 PM
Hi VVA,

Hopefully fixed, please try the updated code  :-)
Title: Re: TabSort.lsp
Post by: kruuger on December 09, 2010, 05:43:49 PM
Hi Lee,

i'm not sure this one was reported but when we select few layouts and click REVERSE, REVERSE then autocad freeze.

kruuger
Title: Re: TabSort.lsp
Post by: Lee Mac on December 09, 2010, 06:01:31 PM
i'm not sure this one was reported but when we select few layouts and click REVERSE, REVERSE then autocad freeze.

Thanks Kruuger, I'll take a look into it  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on December 09, 2010, 07:03:02 PM
Updated to Version 2.1 to provide a quick fix for the issue Kruuger reported.

Yuck... I hate my old code  :ugly:  If I had the time I would rewrite the whole program.  :|
Title: Re: TabSort.lsp
Post by: kruuger on December 10, 2010, 03:09:12 PM
Updated to Version 2.1 to provide a quick fix for the issue Kruuger reported.

Yuck... I hate my old code  :ugly:  If I had the time I would rewrite the whole program.  :|
it might be old but program is a really good tool :)

thank you
kruuger
Title: Re: TabSort.lsp
Post by: Lee Mac on December 10, 2010, 09:03:35 PM
Updated to Version 2.1 to provide a quick fix for the issue Kruuger reported.

Yuck... I hate my old code  :ugly:  If I had the time I would rewrite the whole program.  :|
it might be old but program is a really good tool :)

thank you
kruuger

I'm glad you find it useful  :-)
Title: Re: TabSort.lsp
Post by: Lee Mac on May 17, 2011, 08:58:17 AM
Finally decided it was time to give this program a complete overhaul  8-)

Version 2.2 is a complete rewrite of the program to update many of the old subfunctions, and to reformat the code to get rid of that terrible formatting I used to use.

I haven't added any new functionality, but the program should be more robust and run smoother than the previous version, with a few bugs squashed in the process.

The Find and Replace engine has been completely rewritten, now permitting the user to use self-referencing find and replace terms (for example, replacing 'ABC' with 'AB'), and the visual feedback during the find and replace process has been improved significantly.

With the vast number of changes to the program, I expect there are still a few bugs lurking, but in my preliminary tests, I haven't found anything as yet (but I'm sure you guys will!).

Enjoy!

Lee
Title: Re: TabSort.lsp
Post by: Krushert on May 17, 2011, 12:01:51 PM
Oohhh Sure!   Come out with the revamp a day after I could really used it.   :roll:

I used it yesterday to rename 37 layout tabs in 5 files.  Very handy.  I only need it once in a great while but when I used it is a great time saver.  Thank you.

Now where is that virtual bar tender.  I need to buy you a beer.
Title: Re: TabSort.lsp
Post by: Lee Mac on May 17, 2011, 12:28:36 PM
Oohhh Sure!   Come out with the revamp a day after I could really used it.   :roll:

Hehe  :-P

I used it yesterday to rename 37 layout tabs in 5 files.  Very handy.  I only need it once in a great while but when I used it is a great time saver.  Thank you.

Now where is that virtual bar tender.  I need to buy you a beer.

Cheers Krushert :-) I'm glad you find it useful - I think its one of the few programs I have written which isn't just a novelty app  :lol:
Title: Re: TabSort.lsp
Post by: trogg on May 27, 2012, 11:41:02 AM
Here is a 32X32 pixel .bmp that I use for this routine.

Thanks for sharing with us Lee
Title: Re: TabSort.lsp
Post by: Lee Mac on May 27, 2012, 11:42:39 AM
Cheers Greg, and nice icon - thank you for sharing that  :-)

Out of curiosity, did you create the icon, and if so, what software did you use?
Title: Re: TabSort.lsp
Post by: trogg on May 27, 2012, 12:01:18 PM
Hey Lee,
Glad you like it. I use the free version of "Junior Icon Editor" found here http://download.cnet.com/Junior-Icon-Editor/3000-2195_4-10546738.html (http://download.cnet.com/Junior-Icon-Editor/3000-2195_4-10546738.html) to edit/create icons. Note: This program doesn't save to a normal .bmp format so I end up having to save it as a .png and then convert it...
There is a great program that I would prefer to use but am too cheap at the moment to buy it. It has a 30-day free trial though http://www.iconcool.com/icon-editor.htm (http://www.iconcool.com/icon-editor.htm)

I have found some free (open source) icons from the internet and then modify them. I added the arrow to one that had tabs for your TabSort routine.
The original (sans arrow) is attached
~Greg
Title: Re: TabSort.lsp
Post by: Lee Mac on May 27, 2012, 12:13:52 PM
Thanks for the info Greg, much appreciated  :-)
Title: Re: TabSort.lsp
Post by: alanjt on May 27, 2012, 10:34:10 PM
Dang, Greg, that's cool.  8-)
Title: Re: TabSort.lsp
Post by: miquan on March 06, 2014, 06:01:39 AM
Dear Lee,

Could you possibly add publish function to TABSORT?

Thanks,
Miquan
Title: Re: TabSort.lsp
Post by: Lee Mac on March 06, 2014, 01:27:11 PM
Dear Lee,

Could you possibly add publish function to TABSORT?

Thanks,
Miquan

Hi Miquan,

Being a programmer, I rarely plot/publish anything in AutoCAD and consequently have very limited experience using the PUBLISH command; therefore, I am not sure whether this would be possible to incorporate into this program.

Lee
Title: Re: TabSort.lsp
Post by: miquan on March 07, 2014, 12:25:56 AM
Dear Lee,

Thanks for your reply.

I work with many layout tab in my project, sometimes I need to publish some of them.
I use your tab sort to manage my layouts. It is very useful.

I am very appreciated if anyone can add publish function to this lisp.

Thanks,
Miquan

Title: Re: TabSort.lsp
Post by: Lee Mac on March 08, 2014, 09:38:14 AM
I'm pleased to hear that you find the program so useful in your work - sorry that I cannot assist with this particular enhancement.

From what I've gathered from reading other threads on the forum, you may benefit from using Sheet Sets to publish the layouts in your drawings - though, I'll confess that I have no experience in this area.

Lee