Author Topic: TabSort.lsp  (Read 87535 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #60 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  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #61 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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Gliderider

  • Guest
Re: TabSort.lsp
« Reply #62 on: September 17, 2009, 12:52:09 PM »
Try the Alpha sort, then the # sort, then the Alpha sort again
worked for me...

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #63 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....

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #64 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...


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #65 on: September 17, 2009, 04:22:52 PM »
"Arch Sort" 8-)
or
"Architectural Sort"
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: TabSort.lsp
« Reply #66 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.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #67 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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: TabSort.lsp
« Reply #68 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
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #69 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 ]

T.Willey

  • Needs a day job
  • Posts: 5251
Re: TabSort.lsp
« Reply #70 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:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: TabSort.lsp
« Reply #71 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
  )
)
      )
    )
  )
)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #72 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

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #73 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  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #74 on: September 17, 2009, 07:32:01 PM »
More buttons?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.