Jump to content

Converting text written in inches to feet & inches


Recommended Posts

Posted

Now here I want to convert a existing text written in inches  for example 12" to be converted into 1'-0"

now being a newbie I couldn't figure out a lisp routine to do so, for now I am changing those text and mtext manually.

Could anybody help me out?

Posted

The AutoCAD command Find (and Replace) should do that. Unless there is something you are not mentioning.

Posted

I dont work in feet, long may metric rule, anyway divide the inches by 12 this will give a feet in decimal, 56" = 4.66666667 so the fix is 4' take 56-4*12 = 8" if you have say 56.375 inches then a bit harder, but solvable

 


(defun c:foo ( / num ans foot foots inchs)

(while (setq obj (vlax-ename->vla-object (car (entsel "\nPick "))))

(setq num (atof (vla-get-textstring obj)))

(setq foots (/ num 12))

(setq foot (fix foots))
(setq inchs (- num (* foot 12.0)))

(if (/= inchs 0.0)

(setq ans (strcat (rtos foot  2 0) (chr 39) "-" (rtos inchs 2 0)(chr 34)))

(setq ans (strcat (rtos foot  2 0) (chr 39)))

)

(vla-put-textstring obj ans)

)

(princ)

)

 

 

Posted (edited)

Here's how I would do that if I knew how:

Using BIGAL's example of 56":

 

Integer of 56 divided by 12 = 4. There's the FEET.

56 modulus 12 = 8. There's the INCHES remaining.

Make a program that does that and puts it together how you need it. There's the challenge.

 

Steve

 

 

Edited by StevJ
Posted
3 hours ago, BIGAL said:

anyway divide the inches by 12 this will give a feet in decimal, 56" = 4.66666667 so the fix is 4' take 56-4*12 = 8" if you have say 56.375 inches then a bit harder, but solvable

 

Actually its pretty easy with the remainder function.

 

31 minutes ago, StevJ said:

Integer of 56 divided by 12 = 4. There's the FEET.

56 modulus 12 = 8. There's the INCHES remaining.

Make a program that does that and puts it together how you need it. There's the challenge.

 

I'm a metric-only guy (in our country we don't use imperial) so that guide helped alot, 

Heres some generic solution -

;|
_$ (INCHES->FEETNINCHES 56) >> (4 FT 8)
_$ (INCHES->FEETNINCHES 55) >> (4 FT 7)
_$ (INCHES->FEETNINCHES 56.375) >> (4 FT 8.375)
_$ (INCHES->FEETNINCHES 56.125) >> (4 FT 8.125)
|;
(defun Inches->FeetnInches ( i / feet )
  (if (numberp i)
    (list 
      (setq feet (fix (/ i 12))) 'ft
      (if (zerop feet) i (rem i (* feet 12)))
    )
  )
)

(defun C:test ( / e o r )
  (and 
    (setq e (car (entsel "\nPick Text: ")))
    (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString)
    (numberp (setq r (read (vl-list->string (vl-remove 34 (vl-string->list (vlax-get o 'TextString)))))))
    (setq r (Inches->FeetnInches r))
    (vlax-put o 'TextString 
      (apply ''((a b c) (strcat (vl-prin1-to-string a) "'-" (vl-prin1-to-string c) "\"")) r)
    )
  )
  (princ)
)

 

  • Like 1
Posted
23 minutes ago, Grrr said:

I'm a metric-only guy (in our country we don't use imperial) so that guide helped alot, 

 

I wish it was that way here in the States.

One thing the OP didn't note was whether he needed partial inches as fractions, or decimals as you have done, or if he will always be working with whole inches.

Hey now. That program works really well.

 

Steve

Posted (edited)
(setq str "12.75\"")
(rtos (distof str) 5 2)

 

Edited by Roy_043
Posted

Grr 

(INCHES->FEETNINCHES 56.125) >> (4 FT 8.125)

 

No its 4' 8 1/8 "  🤩

  • Like 1
Posted
21 hours ago, BIGAL said:

Grr 


(INCHES->FEETNINCHES 56.125) >> (4 FT 8.125)

 

No its 4' 8 1/8 "  🤩

 

Thanks for pointing out this little detail, BIGAL !

Perhaps this should work fine:

 

(defun Inches->FeetnInches ( i / feet tmp )
  (if (numberp i)
    (strcat 
      (itoa (setq feet (fix (/ i 12)))) "'" " "
      (itoa (fix (if (zerop feet) i (setq tmp (rem i (* feet 12)))))) " "
      (if (zerop (setq tmp (rem tmp 1))) "0" (apply ''((a b) (strcat (itoa (fix a)) "/" (itoa (fix b)))) (findfraction (* 1000 tmp) 1000))) "\""
      
    )
  )
)


;| Based on: https://social.msdn.microsoft.com/Forums/vstudio/en-US/bf10ca44-4cb9-44c8-a74d-efa9502401d5/round-decimal-to-fraction?forum=vbgeneral
_$ (findfraction 75 100)
(3 4)
_$ (findfraction 125 1000)
(1 8)
_$ (findfraction 20 100)
(1 5)
_$ (findfraction 30 120)
(1 4)
_$ (findfraction 25 100)
(1 4)
|;
(defun findfraction ( a b / s i d c )
  (mapcar 'set '(a b) (mapcar 'fix (list a b)))
  (setq i 1.0)
  (while (and (not s) (<= i a))
    (setq s 
      (and 
        (zerop (rem (setq d (/ a (setq i (1+ i)))) 1))
        (zerop (rem (setq c (/ b i)) 1))
      )
    )
  )
  (if (and s d c) (findfraction d c) (list a b))
)

 

Sample tests:

(mapcar '(lambda (x) (list x '>> (Inches->FeetnInches x)))
  '(56 56.125 56.325 56.625 56.725 56.5 56.25)
)
>>
((56 >> "4' 8 0\"")
  (56.125 >> "4' 8 1/8\"")
  (56.325 >> "4' 8 13/40\"")
  (56.625 >> "4' 8 5/8\"")
  (56.725 >> "4' 8 29/40\"")
  (56.5 >> "4' 8 1/2\"")
  (56.25 >> "4' 8 1/4\"")
)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...