TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Hugo on January 05, 2012, 10:10:27 AM
-
Hello
Can I change a the Lisp so it works well with less.
Will not tolerate it.
Thank you
100.1/10
100.1/9
100.1/09
Hallo
Kann mir einer das Lisp so ändern das es auch mit minus funktioniert.
Bekomme das nicht hin.
Danke
;; INCSUFF -Gilles Chanteau- 2008/01/15
;; Adds the specified increment to a string suffix.
;; Is considered as suffix, all [0-9], [A-Z] and [a-z] characters from
;; the end of the string according to flag value.
;;
;; Arguments
;; str : a string
;; inc : a positive integer
;; flag : an integer, the sum of following binary codes
;; 1 for numbers [0-9]
;; 2 for uppercase [A-Z]
;; 4 for lowercase [a-z]
;;
;; Return
;; The string with incremented suffix (or nil if none valid suffix)
;;
;; Examples :
;; (incsuff "N° 002" 12 1) = "N° 014"
;; (incsuff "Drawing_A" 1 1) = "Drawing_B"
;; (incsuff "test_ZZ9" 1 3) = "test_AAA0"
;; (incsuff "test_ZZ9" 1 1) = "test_ZZ10"
;; (incsuff "12-" 1 nil) = nil
;;
;; Update (13/02/08) : binary codes
(defun incsuff (str inc flag / lst crt pas ind dep quo ret)
(setq lst (reverse (vl-string->list str)))
(while
(and
(setq crt (car lst))
(cond
((< 47 crt 58)
(setq pas 10
ind 48
)
)
((and flag (< 64 crt 91))
(setq pas 26
ind 65
)
)
((and flag (< 96 crt 123))
(setq pas 26
ind 97
)
)
((< 0 quo)
(setq crt (if (= 10 pas)
ind
(1- ind)
)
lst (cons (car lst) lst)
)
)
)
)
(setq dep (- crt ind)
quo (/ (+ dep inc) pas)
ret (cons (+ ind (rem (+ dep inc) pas)) ret)
)
(if (zerop quo)
(setq ret (append (reverse (cdr lst)) ret)
lst nil
)
(if (cdr lst)
(setq lst (cdr lst)
inc quo
)
(setq lst (list ind)
inc (if (= 10 pas)
quo
(1- quo)
)
)
)
)
)
(if ret
(vl-list->string ret)
)
)
-
Show the before and after of what you want for a result.
-
Hello
before "100.1/10"
after "100.1/9 and "100.1/09"
before "100.1/02"
after "100.1/01"
before "100.1/2"
after " 100.1/1"
Danke
-
Oh, you want to subtract the suffix.
Like this
(incsuff "100.1/02" -1 1)
"100.1/01"
I see it doesn't work in all cases.
(incsuff "100.1/10" -1 1)
"100.1/1/"
-
The routine would need to be reworked to handle negative values
but this is a start:
replace this
((< 47 crt 58) ; numbers
(setq pas 10
ind 48
)
)
with this:
((< 47 crt 58) ; numbers
(if (minusp inc)
(setq pas 10
ind 57
)
(setq pas 10
ind 48
)
)
)
This is not a complete solution.
-
@CAB
Thank you
This is the best forum :-) :-) :-)
Danke
Das ist das beste Forum