- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I have a drawing that has some TEXTS and MTEXT with decimal numbers. I need to convert them to fractional numbers. The decimal part needs to be converted and rounded until the 16th denominator, that is, 1/2, 1/4, 3/4, 1/8, 3/8, 5/8, 7/8, 1/16, 3/16, 5/16, 7/16, 9/16, 11/16, 13/16, 15/16.
Let´s say we have "20.25", it will be "20-1/4" ; "1.49" will be "1-1/2"
I need to maintain the text style, color, font, rotation, height, alignment, etc. There are a lot of values to be changed, so I´m looking for a way to do this quickly. I think launching the app and then touching every item once.
I really would appreciate your help finding a solution.
I got this code from AI, but it is not working,
(defun round (num)
(if (< (rem num 1.0) 0.5)
(fix num)
(1+ (fix num))
)
)
(defun c:DecToFrac ( / en ed txt num int frac inc)
(setq en (car (entsel "\nSelect MText with decimal: ")))
(if (and en (setq ed (entget en)))
(progn
(setq txt (cdr (assoc 1 ed)))
(setq num (atof txt))
(setq int (fix num))
(setq frac (rem num 1.0))
(setq inc (round (* frac 16))) ; Assuming 16ths of an inch for fractions
(setq frac-text
(cond
((= inc 0) "")
((= inc 16) (progn (setq int (1+ int)) ""))
((= inc 8) "1/2")
((= inc 4) "1/4")
((= inc 12) "3/4")
((= inc 2) "1/8")
((= inc 6) "3/8")
((= inc 10) "5/8")
((= inc 14) "7/8")
((= inc 1) "1/16")
((= inc 3) "3/16")
((= inc 5) "5/16")
((= inc 7) "7/16")
((= inc 9) "9/16")
((= inc 11) "11/16")
((= inc 13) "13/16")
((= inc 15) "15/16")
)
)
(setq new-txt (strcat (itoa int) (if frac-text (strcat "-" frac-text) "")))
(entmod (subst (cons 1 new-txt) (assoc 1 ed) ed))
)
)
(princ)
)
Solved! Go to Solution.