PDA

View Full Version : Is there a way to substitute 0" with 00"?


boesiii
2006-02-23, 10:15 PM
I have routine that asks the user for two points then displays the bearing and distance between points. It displays the angle in survey units. Is there a way for it to substitue 0" with 00"?

When I try to use the function (vl-string-subst "00"" "0"" text_ang), it get hung up on the quotes.

(defun midpoint ()
(setq pt1_x (car pt1)
pt2_x (car pt2)
pt1_y (cadr pt1)
pt2_y (cadr pt2)
midpt (list (+ pt1_x (/ (- pt2_x pt1_x) 2)) (+ pt1_y (/ (- pt2_y pt1_y) 2)))
)
)



(defun dtr (a)
(* (/ a 180.00) pi)
)


(defun rtd (a)
(* (/ a pi) 180.0)
)


(defun c:bad ()
(setq c_textstyle (getvar "textstyle"))
(setq c_textsize (getvar "textsize"))
(setq c_ltscale (getvar "ltscale"))
(if (= "textsize" 0) (setvar "textsize" 1))
(setq pt1 (getpoint "\nPick the first Point: ")
pt2 (getpoint "\nPick the second Point: ")
dist (distance pt1 pt2 )
ang (angle pt1 pt2)
num_ang (rtd ang)

text_ang (angtos ang 4 4)
text_dist (strcat (rtos dist 2 2) "'")
bad (strcat text_ang " " text_dist "'")
)
(midpoint)
(setq real_bad (vl-string-subst "%%d" "d" text_ang))
(setq c_osmode (getvar "osmode"))
(setvar "osmode" 0)
(command "mtext" midpt "r" num_ang "j" "mc" "w" "0" real_bad text_dist "")
(setvar "osmode" c_osmode)
(princ "\n************BAD worked**************")
(princ)
)

rad.77676
2006-02-23, 10:40 PM
Change Precision here:

text_ang (angtos ang 4 4)

jwanstaett
2006-02-23, 10:42 PM
use this code

(vl-string-subst "00\"" "0\"" text_ang),




Within quoted strings, the backslash (\) character allows control characters (or escape codes) to be included.
\" is read as "
\\ is read as \

rad.77676
2006-02-24, 01:10 AM
You shouldn't rewrite something that isn't broken.


(defun midpoint ()
(setq pt1_x (car pt1)
pt2_x (car pt2)
pt1_y (cadr pt1)
pt2_y (cadr pt2)
midpt (list (+ pt1_x (/ (- pt2_x pt1_x) 2)) (+ pt1_y (/ (- pt2_y pt1_y) 2)))
)
)



(defun dtr (a)
(* (/ a 180.00) pi)
)


(defun rtd (a)
(* (/ a pi) 180.0)
)


(defun c:bad ()
(setq c_textstyle (getvar "textstyle"))
(setq c_textsize (getvar "textsize"))
(setq c_ltscale (getvar "ltscale"))
(if (= "textsize" 0) (setvar "textsize" 1))
(setq pt1 (getpoint "\nPick the first Point: ")
pt2 (getpoint "\nPick the second Point: ")
dist (distance pt1 pt2 )
ang (angle pt1 pt2)
num_ang (rtd ang)

text_ang (angtos ang 4 6)
text_dist (strcat (rtos dist 2 2) "'")
bad (strcat text_ang " " text_dist "'")
)
(midpoint)
(setq real_bad (vl-string-subst "%%d" "d" text_ang))
(setq c_osmode (getvar "osmode"))
(setvar "osmode" 0)
(command "mtext" midpt "r" num_ang "j" "mc" "w" "0" real_bad text_dist "")
(setvar "osmode" c_osmode)
(princ "\n************BAD worked**************")
(princ)
)

(angtos ang 4 6)
The last number in angtos is the precision.
Hope this helps!
Rob

boesiii
2006-02-24, 01:32 AM
Rad it wasn't about precision. I wanted all zero's to be double zero's.

Thanks Jwan, that will probably work

rad.77676
2006-02-24, 09:53 PM
Rad it wasn't about precision. I wanted all zero's to be double zero's.


My misunderstanding, sorry about that! :Oops: