;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; for CoCreate SolidDesigner ;; Description: ;; Sort - Liste sortieren ;; how to sort - test with defdialog + local function ;; ;; Reference : https://ww3.cad.de/foren/ubb/Forum92/HTML/001024.shtml#000010 ;; Docu : https://support.ptc.com/help/creo_elements_direct/r20.5.0.0/advanced_documentation/integration_kit/reference/strings.html#sd-string< ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Filename : cadde_92_001024b.lsp ;; Version : 1.0 ;; Created : Sat Dec 10 13:55:04 CEST 2022 ;; Modified : Sat Dec 10 15:28:49 CET 2022 ;; Author : der_Wolfgang@forum@cad.de ;; Download : cad.de ;; SD-Version : developed with PE80 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :cadde-wt) (use-package :oli) (sd-defdialog 'cadde_92_001024b :dialog-title "Test Sort Local Func" :mutual-exclusion '(sort_by_def01 sort_by_def02 sort_by_local) :toolbox-button :force :variables '( (my_list :value-type :string :title "List" :prompt-text "Enter list of comma / blank separated values" :initial-value "18.1 zehn 10 zwölf 12 eins 1 drei 4 zwo 42 38.4 " ) (sortit :title "Sort it" :push-action (when my_list (sort-my-list)) ) (sort_by_def01 :title "by defun" :value-type :boolean :toggle-type :wide-toggle) (sort_by_def02 :title "by local as defun" :value-type :boolean :toggle-type :wide-toggle) (sort_by_local :title "by local function" :value-type :boolean :toggle-type :wide-toggle) ) :local-functions '( (sort-by (a b) (let ((n1 (sd-read-from-string a)) (n2 (sd-read-from-string b)) ) (if (and (numberp n1) (numberp n2)) (< n1 n2) (string< a b) ) ) ) (sort-my-list () (let (sorted-list) (setq sorted-list (sd-string-split (sd-string-replace my_list "," " ") " ")) (setq sorted-list (mapcar 'sd-string-trim sorted-list)) (setq sorted-list (delete-if '(lambda (s) (zerop (length s))) sorted-list)) (pprint sorted-list) ;(trace sort) (setq sorted-list (cond (sort_by_local (sort sorted-list 'sort-by)) (sort_by_def01 (sort sorted-list 'reverse-sort-as-strings)) (sort_by_def02 (sort sorted-list 'sort-by-number-or-string)) ) ) ;(untrace sort) (pprint sorted-list) ) ) ) ;; end local-functions :after-initialization '(sd-show-console-window) ) (defun reverse-sort-as-strings (s1 s2) (sd-string> s1 s2) ) (trace reverse-sort-as-strings) (defun sort-by-number-or-string (a b) (let ((n1 (sd-read-from-string a)) (n2 (sd-read-from-string b)) ) (if (and (numberp n1) (numberp n2)) (< n1 n2) (string< a b) ) ) ) (trace sort-by-number-or-string)