Jump to content

help with routine...numerical filter


Recommended Posts

Posted
(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

Posted

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
    )
)

 

  • Like 3
  • Thanks 1
Posted

Excellent master, it worked perfectly  thanks

Posted

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)))
)

 

  • Like 1
  • Thanks 1
Posted

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
)

 

  • Like 1
  • Thanks 1
Posted

I do same as Steven P with 1 little change

 

(if (< pre 10)(setq tmp "00"))

 

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...