You are here:

AutoCAD/Getreal string in a Lisp routine

Advertisement


Question
Hello Bill, long time since I bothered You last time! ;)

Now I have a quite easy question for you, I think.

In a lisp I need to ask the drawing scale from the user, eg. 1:2, 12:100 or 100:12.
Both numbers can be whatever, but usually 1-3 digits (between 1 and 100). Now I need to separate those numbers (for later use) and I donīt want to ask them one by one.
I know I have to use getreal and substr functions, but how I calculate the place of the ":" mark? Before it there can be 1,2 or 3 (or even more) digits.

Thank you!

<<< Niko >>>  

Answer
I may be copping out, but I can't think of a way to identify the number of characters before and after another character.  I would use this approach:

(defun c:test ()
  (setq first (getreal "\nFirst number of ratio:  ")); could also use getint
  (setq second (getreal "\nSecond number of ratio:  ")); could also use getint
  (setq quotient (/ first second))
  (princ quotient)
  (princ)
)

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.