Solved! Go to Solution.
Solved by _Tharwat. Go to Solution.
e.g.
(if (eq <inputs) correct) (do this) (otherwise print a message of your desire ) )
Odin,
that's depands on what input the user should be enter...if the attribute is expecting a numeric value?
then you can do somthing like this?:
(setq real_value (getreal "\nEnter real value: ")) ; require a value from 0 to 100
(if (and
(>= real_value 0)
(<= real_value 100)
)
(do_insert_block)
(prompt "\n*invalid value*")
)
if the attribute is expecting a string value (like a key option)?
then you can do somthing like that:
(initget "Red Yellow Green Cyan") ; note the capital letter at start of each key word option
(setq color (getkword "\nChange color -> Red/Yellow/Green/Cyan: "))
the user can enter only R for Red, Y for Yellow (like any other key option in any other
standard AutoCAD Command
if user misses to specify the right key option? then autolisp it self will alert him and continue
to pause until the right value (allowed) is given.
Cheers,
Moshe
@Moshe-A wrote:....if the attribute is expecting a numeric value?
then you can do somthing like this?:
(setq real_value (getreal "\nEnter real value: ")) ; require a value from 0 to 100
(if (and
(>= real_value 0)
(<= real_value 100)
)
(do_insert_block)
(prompt "\n*invalid value*")
)
....
Two refinements I would suggest:
Numerical value comparison functions can take more than two arguments. So in place of
(and
(>= real_value 0)
(<= real_value 100)
)
you can do simply:
(<= 0 real_value 100)
And if you format it something like this:
(while
(not
(<=
0 ; minimum allowable value
(setq real_value (getreal "\nEnter real value: "))
100 ; maximum allowable value
); <=
); not
(prompt "\nYou must give a value between 0 and 100.")
); while
.... go on with insertion, feeding values in where Attribute prompts occur ....
it will work like the (initget)/(getkword) approach, in that it will keep asking for input until a valid value is supplied, rather than just taking one input, and if it's wrong, putting up a message and stopping.
Can't find what you're looking for? Ask the community or share your knowledge.