Author Topic: TabSort.lsp  (Read 87527 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #105 on: September 19, 2009, 09:21:56 PM »
Thanks, I'll give it a try later tonight or tomorrow.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: TabSort.lsp
« Reply #106 on: September 20, 2009, 10:31:43 AM »
First post updated to Version 1.7 to include the features as listed  ;-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: TabSort.lsp
« Reply #107 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)
          )
        )
      )
    )
  )
)
« Last Edit: September 20, 2009, 02:46:15 PM by gile »
Speaking English as a French Frog

Lee Mac

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

Lee Mac

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #110 on: September 20, 2009, 06:08:45 PM »
OK where is the HELP button to explain all this?  :evil:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

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

CAB

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

Lee Mac

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

CAB

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

Lee Mac

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

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: TabSort.lsp
« Reply #116 on: September 21, 2009, 02:32:30 PM »
Talk about 'out of control'. LoL
Very nice Lee.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

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

Lee Mac

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: TabSort.lsp
« Reply #119 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.
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.