Author Topic: Getting a string's numeric value  (Read 3336 times)

0 Members and 1 Guest are viewing this topic.

bman

  • Guest
Getting a string's numeric value
« on: September 29, 2005, 12:01:46 PM »
How would I go about getting a numeric value from a text entity & change the elevation of a pline to match that value?

Code: [Select]
(defun c:chel ( / xel ent)
(setq xel (;;;;;;;;;HERE'S WHERE I'M HAVING PROBLEMS;;;;;entsel "Select Text Value:"))))))
(setq ent (entsel "Select Pline to change elev: "))
(command "change" ent "" "p" "e" xel "c" "6" "")
)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Getting a string's numeric value
« Reply #1 on: September 29, 2005, 12:07:02 PM »
you could use (atof "3.9")  to convert the string "3.9" to the real number 3.9
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Peter Jamtgaard

  • Guest
Re: Getting a string's numeric value
« Reply #2 on: September 29, 2005, 12:28:19 PM »
Code: [Select]
(defun c:chel ( / xel ent)
 (setq xel (cdr (assoc 1 (entget (car (entsel "\nSelect Text Value:"))))))
 (setq ent (car (entsel "\nSelect Pline to change elev: ")))
 (command "change" ent "" "p" "e" xel "c" "6" "")
)



How would I go about getting a numeric value from a text entity & change the elevation of a pline to match that value?

Code: [Select]
(defun c:chel ( / xel ent)
(setq xel (cdr (assoc 1 (car (entsel "Select Text Value:")))))
(setq ent (entsel "Select Pline to change elev: "))
(command "change" ent "" "p" "e" xel "c" "6" "")
)

bman

  • Guest
Re: Getting a string's numeric value
« Reply #3 on: September 29, 2005, 01:12:04 PM »
Sweet!!! thanks Peter!!!

Bob Wahr

  • Guest
Re: Getting a string's numeric value
« Reply #4 on: September 29, 2005, 01:28:46 PM »
Would be nice to have a check to make sure that the text is a number.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Getting a string's numeric value
« Reply #5 on: October 02, 2005, 02:44:05 PM »
I have this made old one...


Code: [Select]
(defun C:TRE()
(setq num1 nil)
(setq ent_sel1 (entsel "Select text to edit..."))
  (if (= ent_sel1 nil)(exit))
  (setq ent_sel2 (entget (car ent_sel1)))
  (setq line1 (cdr (assoc 1 ent_sel2)))
  (if (= line1 nil)(exit))

(setq len1 (strlen line1))
  (setq val 1)
(repeat len1
  (progn
  (setq ftxt (substr line1 val 1))
  (if (numberp (read ftxt))(addnum))
  (setq val (+ val 1)))
  )
 (alert num1))


(defun addnum ()
(if (= num1 nil) (setq num1 ""))
  (setq num1 (strcat num1 ftxt)))

but if someone ha another routine making same thing...or better
and the code is shorter than this....I'll be curious to see it.

thanks.
Keep smile...