(DEFUN C:test (/)
(DEFUN FTDEC (ASTR / BUF RES C R1)
(SETQ BUF "" RES 0.0)
(WHILE (> (STRLEN ASTR) 0)
(SETQ C (SUBSTR ASTR 1 1) ASTR (SUBSTR ASTR 2))
(COND
((= C "'")
(SETQ RES (* (ATOF BUF) 12.0) BUF "" ASTR (SUBSTR ASTR 2))
)
((= C "/")
(SETQ R1 (ATOF BUF) BUF "")
)
((= C " ")
(SETQ RES (+ RES (ATOF BUF)) BUF "")
)
((/= C (CHR 34))
(SETQ BUF (STRCAT BUF C))
)
)
)
(IF R1
(+ RES (/ R1 (ATOF BUF)))
(+ RES (ATOF BUF))
)
);end while
;
(SETVAR "CMDECHO" 0)
(SETQ DSCL (GETVAR "DIMSCALE"))
(SETQ ENT1 (ENTSEL))
(SETQ ENT2 (ENTGET (CAR ENT1)))
(SETQ ANG1 (ATOF (ANGTOS (CDR (ASSOC 50 ENT2)))))
(SETQ NUM4 (CDR (ASSOC 1 ENT2)))
(IF (WCMATCH NUM4 "%%*")
(SETQ NUM4 (SUBSTR NUM4 4))
)
(setq Mort (CDR (ASSOC 0 ENT2)))
(SETQ NUM5 (FTDEC NUM4))
(IF (= NUM4 nil) (SETQ NUM4 0))
(SETQ P1 (* num5 25.4))
(IF (= MORT "TEXT")
(SETQ P4 (STRCAT (cdr (assoc 1 ent2))" (" (RTOS P1 2 0) "mm)"))
);END IF
(IF (= ANG1 0) (SETQ SPC (STRCAT "@0,-" (RTOS (* 0.2212 DSCL) 2))))
(IF (= ANG1 90) (SETQ SPC (STRCAT "@" (RTOS (* 0.2212 DSCL) 2) ",0")))
(IF (= ANG1 180) (SETQ SPC (STRCAT "@0," (RTOS (* 0.2212 DSCL) 2))))
(IF (= ANG1 270) (SETQ SPC (STRCAT "@-" (RTOS (* 0.2212 DSCL) 2) ",0")))
(SETVAR "CMDECHO" 1)
(SETQ ent2 (SUBST (CONS 1 P4) (ASSOC 1 ent2) Ent2))
(ENTMOD Ent2)
(PRINC)
)
Consider using the position of the first "space" when placing the 'metric' string:Code - Auto/Visual Lisp: [Select]
(defun c:test (/ num str x idx )
;;+++++++++++++++++++++++++++++++
;; convert the text to a number
;;+++++++++++++++++++++++++++++++
(defun txt2num (txt) ; CAB 10/2005
(cond
((distof txt 5))
((distof txt 2))
((distof txt 1))
((distof txt 4))
((distof txt 3))
)
)
(setq str "12'-6 1/2\" dia circle")
(setq idx (strlen str))
(while (not (numberp (setq x (txt2num (substr str 1 idx)))))
(setq num x idx (1- idx)))
(setq newstr (strcat (substr str 1 idx) "(my mm)" (substr str idx)))
)
Consider using the position of the first "space" when placing the 'metric' string:Code - Auto/Visual Lisp: [Select]
Maybe it's just me, but I see a problem with that method. :lol:
Play with this.Code: [Select](defun c:test (/ num str x idx )
;;+++++++++++++++++++++++++++++++
;; convert the text to a number
;;+++++++++++++++++++++++++++++++
(defun txt2num (txt) ; CAB 10/2005
(cond
((distof txt 5))
((distof txt 2))
((distof txt 1))
((distof txt 4))
((distof txt 3))
)
)
(setq str "12'-6 1/2\" dia circle")
(setq idx (strlen str))
(while (not (numberp (setq x (txt2num (substr str 1 idx)))))
(setq num x idx (1- idx)))
(setq newstr (strcat (substr str 1 idx) "(my mm)" (substr str idx)))
)
_$ (AddMetric "12'-6\"")
"12'-6\" (3810mm)"
_$ (AddMetric "12'-6\" dia circle")
"12'-6\" (3810mm) dia circle"
_$ (AddMetric "this is a 12'-6 1/2\" dia circle")
"this is a 12'-6 1/2\" (3823mm) dia circle"
_$ (AddMetric "circle dia = 12'-6 1/2\"")
"circle dia = 12'-6 1/2\" (3823mm)"
_$ (AddMetric "circle-dia = 12'-6 1/2\"")
"circle-dia = 12'-6 1/2\" (3823mm)"
_$ (AddMetric "circle '/ \"-dia = 12'-6 1/2\"")
"circle '/ \"-dia = 12'-6 1/2\" (3823mm)"
_$ (AddMetric "No. 1 circle '/ \"-dia = 12'-6 1/2\"")
"No. 1 circle '/ \"-dia = 12'-6 1/2\" (3823mm)"
Seems to work for the cases I can think of.FWIW -
Break Strings to List: