Convert an mtext number to inches

Convert an mtext number to inches

Anonymous
Not applicable
2,032 Views
13 Replies
Message 1 of 14

Convert an mtext number to inches

Anonymous
Not applicable

Please help, I have a mtext number 0.45 and I would like to click on it and it would become 5-3/8"

I have search all over for an autolisp to do it but found no result.

Thanks for all the help you can offer.

0 Likes
Accepted solutions (2)
2,033 Views
13 Replies
Replies (13)
Message 2 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

Please help, I have a mtext number 0.45 and I would like to click on it and it would become 5-3/8"

I have search all over for an autolisp to do it but found no result.

Thanks for all the help you can offer.


Not sure how  0.45 =  5-3/8" ?  Is this has nothing to do with arithmetic? or just direct Find and Replace string?

 

 

 

 

0 Likes
Message 3 of 14

Anonymous
Not applicable

It's 0.45'

Approximately equals to 5-3/8"

0 Likes
Message 4 of 14

pbejse
Mentor
Mentor

 

I see. feet to inches then

 

(rtos (cvunit 0.45 "feet" "inch") 4 3)

 

0 Likes
Message 5 of 14

Anonymous
Not applicable

I'm sorry I have to rewrite my request to make it clearer.

Let say I have a bunch of mtext and text and in a drawing and they are elevations, 0.45, 0.78 etc......

I would like to convert these to inch and fraction of an inch.

0 Likes
Message 6 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

I'm sorry I have to rewrite my request to make it clearer.

Let say I have a bunch of mtext and text and in a drawing and they are elevations, 0.45, 0.78 etc......

I would like to convert these to inch and fraction of an inch.


Is that just "0.45" or a bigger part of a string like ELEV. + 0.45"?

 

0 Likes
Message 7 of 14

Anonymous
Not applicable

0.45 is all it shows, no feet mark and it's not an attribute.

0 Likes
Message 8 of 14

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

0.45 is all it shows, no feet mark and it's not an attribute.


 

  (defun c:demo (/ ss i ent)
    (if (setq ss (ssget "_:L" '((0 . "MTEXT,TEXT") (1 . "*#.#*"))))
	 (repeat (setq i (sslength ss))
	   (setq ent (entget (ssname ss (setq i (1- i)))))
	   (if (numberp (Read (setq str (cdr (assoc 1 ent)))))
		(entmod
		  (subst
		    (cons 1 (rtos (cvunit (distof str) "feet" "inch") 4 3))
		    (assoc 1 ent)
		    ent
		  ) ;_ end of subst
		) ;_ end of entmod
	   ) ;_ end of if
	 ) ;_ end of repeat
    ) ;_ end of if
  ) ;_ end of defun
            

HTH

 

0 Likes
Message 9 of 14

hak_vz
Advisor
Advisor
Accepted solution

 Written by someone from SI world. I hope its ok.

 

 

(defun C:inch_fract ( / e ent foot inch man res fract fradec i *error*)
(defun *error* () (princ))

  (setq 
    e (entsel "\nSelect text object >")
    ent (entget (car e))
    foot (atof(cdr(assoc 1 ent)))
    foot_fix (fix foot)
    rest_foot (- foot foot_fix)
    inch (* rest_foot 12.0)
    man (fix inch)
    res (- inch man)
    fract '(("1" "64")("1" "32")("3" "64")("1" "16")("5" "64")("3" "32")("7" "64")("1" "8")("9" "64")("5" "32")("11" "64")("3" "16")("13" "64")
            ("7" "32")("15" "64")("1" "4")("17" "64")("9" "32")("19" "64")("5" "16")("21" "64")("11" "32") ("23" "64")("3" "8")("25" "64")("13" "32")
            ("27" "64")("7" "16")("29" "64")("15" "32")("31" "64")("1" "2")("33" "64")("17" "32")("35" "64")("9" "16")("37" "64")("19" "32")("39" "64")
            ("5" "8")("41" "64")("21" "32")("43" "64")("11" "16")("45" "64")("23" "32")("47" "64")("3" "4")("49" "64")("25" "32")("51" "64")("13" "16")
            ("53" "64")("27" "32")("55" "64")("7" "8")("57" "64")("29" "32")("59" "64")("15" "16")("61" "64")("31" "32")("63" "64")
          )
    fradec 
    (list 0.015625 0.03125 0.046875 0.0625 0.078125 0.09375 0.109375 0.125 0.140625 0.15625 0.171875 0.1875 0.203125 0.21875 0.234375 0.25 0.265625 0.28125 0.296875 0.3125 0.328125 0.34375 0.359375 0.375 0.390625 0.40625 0.421875 0.4375 0.453125 0.46875 0.484375 0.0.5 0.515625 0.53125 0.546875 0.5625 0.578125 0.59375 0.609375 0.625 0.640625 0.65625 0.671875 0.6875 0.703125 0.71875 0.734375 0.75 0.765625 0.78125 0.796875 0.8125 0.828125 0.84375 0.859375 0.875 0.890625 0.90625 0.921875 0.9375 0.953125 0.96875 0.984375 )
    i 0)

    (while (< (nth i fradec) res) (setq i (+ i 1)))
    (setq frac_str (strcat (itoa foot_fix) " " (itoa man) "-" (car(nth i fract)) "/" (cadr(nth i fract)))
    
          ent (subst (cons 1 frac_str)(assoc 1 ent)  ent)
          ent (entmod ent)
    )
    (princ)  
  )

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 14

john.uhden
Mentor
Mentor

Mr. Bond (James I presume):

 

Having been inspired by @pbejse, I decided to make one that finds all the decimal pieces inside mtexts and convert them from apparent feet to architectural feet and inches.

 

(defun wcsearch (str match / pos n1 n2 found)
  (setq pos 1 n2 1)
  (while (and (not n1)(not found)(<= pos  (strlen str)))
    (if (wcmatch (substr str pos)(strcat match "*"))
      (progn
        (setq n1 pos)
        (while (not (wcmatch (substr str n1 n2) match))
          (setq n2 (1+ n2))
        )
        (setq found (substr str n1 n2))
      )
      (setq pos (1+ pos))
    )
  )
  found
)

(defun c:demo2 ( / matches ss i ent old found new)
  (setq matches '("#.##" "##.##" "###.##" "####.##"))
   (if (setq ss (ssget "_:L" '((0 . "MTEXT,TEXT") (1 . "*#.##*"))))
      (repeat (setq i (sslength ss))
        (setq ent (entget (ssname ss (setq i (1- i)))))
        (setq old (cdr (assoc 1 ent)) new old)
        (while (setq found (car (vl-remove nil (mapcar (function (lambda (x)(wcsearch new x))) matches))))
          (setq new (vl-string-subst (rtos (* 12 (distof found)) 4 3) found new))
        )
        (if (/= old new)(entmod (subst (cons 1 new)(assoc 1 ent) ent)))
     )
   )
)

NOTES:

The wcsearch function is not built to use wildcards other than #

You can change the matches variable as you see fit for your conditions

Be careful of your setting for DIMZIN.  Mine was 0.

 

For example, it turned this:

THE ELEVATIONS AT THE FOLLOWING POINTS ARE:
"A" = 22.43
"B" = 8.75
"C" = 133.69

 

into this:

 

THE ELEVATIONS AT THE FOLLOWING POINTS ARE:
"A" = 22'-5 1/8"
"B" = 8'-9"
"C" = 133'-8 1/4"

John F. Uhden

0 Likes
Message 11 of 14

pbejse
Mentor
Mentor

@john.uhden wrote:

Mr. Bond (James I presume):

 

Having been inspired by @pbejse, I decided to make one that finds all the decimal pieces inside mtexts and convert them from apparent feet to architectural feet and inches.


"A" = 22.43.. "A" = 22'-5 1/8"...


Nice Idea, 

 

I was thinking of simply removing  the precision on the code i posted here 

 

(cons 1 (rtos (cvunit (distof str) "feet" "inch") 4 3))

to

(cons 1 (rtos (cvunit (distof str) "feet" "inch") 4 ))

and leave the precision value to  system variable LUPREC for consistency.

 

 

Luprec value 2
22.43 -> 22'-5 1/4"
3 22'-5 1/8" 4 22'-5 3/16" 5 22'-5 5/32" ....

HTH

 

 

 

0 Likes
Message 12 of 14

pbejse
Mentor
Mentor

@john.uhden wrote:

Mr. Bond (James I presume):

 

Having been inspired by @pbejse, I decided to make one that finds all the decimal pieces inside mtexts and convert them from apparent feet to architectural feet and inches.


"A" = 22.43.. "A" = 22'-5 1/8"...


Nice Idea, 

 

I was thinking of simply removing  the precision on the code i posted here 

 

(cons 1 (rtos (cvunit (distof str) "feet" "inch") 4 3))

to

(cons 1 (rtos (cvunit (distof str) "feet" "inch") 4 ))

and leave the precision value to  system variable LUPREC for consistency.

 

 

Luprec value 2
22.43 -> 22'-5 1/4"
3 22'-5 1/8" 4 22'-5 3/16" 5 22'-5 5/32" ....

HTH

 


@john.uhden wrote:

Mr. Bond (James I presume):

 


- Yesh money penny- 

 

[ at least that is what the user profile shows anyway ]

 

0 Likes
Message 13 of 14

john.uhden
Mentor
Mentor

1st - My routine was written assuming from your example that the existing precision was to the hundredth of a foot.

 

2nd - LUPREC=3 is to the nearest 1/8 inch, which is very close to a hundredth of a foot (actually 1/96)

 

3rd - My routine may wreak havoc on any embedded mtext formatting.

John F. Uhden

0 Likes
Message 14 of 14

Anonymous
Not applicable

Thank you everyone, they all worked wonderfully.

0 Likes