leonucadomi Posted September 21, 2023 Posted September 21, 2023 (setq nodwg (getstring "\nEnter the number")) I have a routine to rename dwg files. I use this line to enter part of the name The data entered is always between 001 to 999 I would like you to help me with a filter so that it only accepts this number range and not letters. I appreciate any comments thanks Quote
Lee Mac Posted September 21, 2023 Posted September 21, 2023 Consider something like the following: (while (not (or (= "" (setq nodwg (getstring "\nEnter the number <exit>: "))) (wcmatch nodwg "###") ) ) (princ "\nNumber must be in the range 001-999.") ) (if (/= "" nodwg) (progn ;; do stuff ) ) 3 1 Quote
leonucadomi Posted September 21, 2023 Author Posted September 21, 2023 Excellent master, it worked perfectly thanks Quote
Steven P Posted September 21, 2023 Posted September 21, 2023 My first thought was to use getint, below works if you want the file number to have leading zeros (for numbers below 100). (defun c:test ( / tmp pre) (setq tmp "") (setq pre (getint "Enter Drawing Number: ")) (if (< pre 10)(setq tmp "0")) (if (< pre 100)(setq tmp (strcat tmp "0"))) (setq pre (strcat tmp (rtos pre))) ) 1 1 Quote
mhupp Posted September 21, 2023 Posted September 21, 2023 This is what I use for leading 0's (defun AT:NumFix (s n) ;; Fix number string with leading zeros ;; s - Number string to fix ;; n - Number of characters for final string ;; Alan J. Thompson, 10.29.09 ;; (AT:NumFix i 3) i= 1 = 001 (if (< (strlen s) n) (AT:NumFix (strcat "0" s) n) s ) ) (defun c:test (/ pre tmp) (if (and (setq pre (getint "Enter Drawing Number: ")) (> pre 0) (< pre 999)) (setq tmp (AT:NumFix (itoa pre) 3)) (Alert "\nNumber must be in the range 001-999.") ) tmp ) 1 1 Quote
BIGAL Posted September 21, 2023 Posted September 21, 2023 I do same as Steven P with 1 little change (if (< pre 10)(setq tmp "00")) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.