Decimal inches to architectural ft-in

Decimal inches to architectural ft-in

dlalmendinger
Participant Participant
928 Views
11 Replies
Message 1 of 12

Decimal inches to architectural ft-in

dlalmendinger
Participant
Participant

Hi everyone,

 

I'm looking to turn TOTAL inches into FT-IN. My code is posted below. I'm almost positive there is a better way to do this, we can get to that later. I would like to finish this code out first as I'm still green to LISP. I know enough to be dangerous LOL.

What I'm am looking for is in my answer to show up in the command line nice and pretty. Right now if 25 is the number I type in, "2'-1''" is my answer in the command line. I would like the answer to appear 2'-1" in command line. I know this won't cut it for fractions, but that is the later part.

Any and all help would be much appreciated.

 

Derek

 

(defun c:in ()
(setvar "cmdecho" 0)
;---Get User Input------------------------------------------------------------------------
(setq in2  (getreal "\nInches (in decimal): ")) ;gets Total Number of Inches (real number)
;---Isolate FT----------------------------------------------------------------------------
(setq in-a (fix in2))                           ;in2 real to Integer (DOES NOT ROUND UP)
(setq ft-a (/ in-a 12))                         ;gets feet for solution
(setq ft-b (itoa ft-a))                         ;turn solution into STRING
;---Isolate INCHES------------------------------------------------------------------------
(setq in-b (* (- (/ in2 12) ft-a) 12))          ;gets inches for solution
(setq in-c (fix in-b))                          ;in2 real to Integer (DOES NOT ROUND UP)
(setq in-d (itoa in-c))                         ;turn solution into STRING
;---Solution------------------------------------------------------------------------------
(strcat ft-b "'-" in-d "''")                    ;answer


)

 

0 Likes
Accepted solutions (1)
929 Views
11 Replies
Replies (11)
Message 2 of 12

dlalmendinger
Participant
Participant

I'm closer. Now I just need to clean up line 14, need the (2) apostrophes to be a close quote for the inches designator.

(defun c:in ()
(setvar "cmdecho" 0)
;---Get User Input------------------------------------------------------------------------
(setq in2  (getreal "\nInches (in decimal): ")) ;gets Total Number of Inches (real number)
;---Isolate FT----------------------------------------------------------------------------
(setq in-a (fix in2))                           ;in2 real to Integer (DOES NOT ROUND UP)
(setq ft-a (/ in-a 12))                         ;gets feet for solution
(setq ft-b (itoa ft-a))                         ;turn solution into STRING
;---Isolate INCHES------------------------------------------------------------------------
(setq in-b (* (- (/ in2 12) ft-a) 12))          ;gets inches for solution
(setq in-c (fix in-b))                          ;in2 real to Integer (DOES NOT ROUND UP)
(setq in-d (itoa in-c))                         ;turn solution into STRING
;---Solution------------------------------------------------------------------------------
(princ (strcat ft-b "'-" in-d "''"))            ;answer
(princ)

)

 

0 Likes
Message 3 of 12

dlalmendinger
Participant
Participant

Figured it out, needed \" inside of the qoutes.

 

Now for the later part. There must be an easier way with some combination of  LUNITS, or probably RTOS to shorten my code. I will continue to play with it, but at the moment I need to take off. 

 

Any help is apprectiated.

 

(defun c:in ()
(setvar "cmdecho" 0)
;---Get User Input------------------------------------------------------------------------
(setq in2  (getreal "\nInches (in decimal): ")) ;gets Total Number of Inches (real number)
;---Isolate FT----------------------------------------------------------------------------
(setq in-a (fix in2))                           ;in2 real to Integer (DOES NOT ROUND UP)
(setq ft-a (/ in-a 12))                         ;gets feet for solution
(setq ft-b (itoa ft-a))                         ;turn solution into STRING
;---Isolate INCHES------------------------------------------------------------------------
(setq in-b (* (- (/ in2 12) ft-a) 12))          ;gets inches for solution
(setq in-c (fix in-b))                          ;in2 real to Integer (DOES NOT ROUND UP)
(setq in-d (itoa in-c))                         ;turn solution into STRING
;---Solution------------------------------------------------------------------------------
(princ (strcat ft-b "'-" in-d "\""))            ;answer
(princ)

)

 

0 Likes
Message 4 of 12

CodeDing
Advisor
Advisor
Accepted solution

@dlalmendinger ,

 

I'm about to blow your mind, because there is a 100% better way to accomplish this.

The (rtos ...) function turns a Real TO String, and can format it for us.

(defun c:IN ( / inches result1 result2)
  ;; ----- Get User Input -----
  (initget 1)
  (setq inches  (getreal "\nInches (in decimal): ")) ;gets Total Number of Inches (real number)

  (setq result1 (rtos inches 3 10))
  (prompt (strcat "\nHere is Inches in Engineering Units: " result1))

  (setq result2 (rtos inches 4 8))
  (prompt (strcat "\nHere is Inches in Architectural Units: " result2))

  (princ)
)

 

Best,

~DD

0 Likes
Message 5 of 12

paullimapa
Mentor
Mentor

Look up rtos function using Architectural mode 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 12

dlalmendinger
Participant
Participant

Haha that is awesome! I never thought of displaying both architectural and engineering solutions, I love that!

Yes, I was looking at the RTOS function this morning a was thinking that was going to be the better option. Am I correct that the 10 and 8 are for precision? Lower numbers are lower precision and higher numbers are higher precision? See pic below.

 

Capture.JPG

0 Likes
Message 7 of 12

paullimapa
Mentor
Mentor

Yes that’s what the 2nd number is for


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@dlalmendinger wrote:

.... Am I correct that the 10 and 8 are for precision? Lower numbers are lower precision and higher numbers are higher precision? ....


For future reference, you can read about what all the arguments to a function are for, the kinds of values to be supplied, what the functions return, etc., in the >AutoLisp Reference<.

Kent Cooper, AIA
0 Likes
Message 9 of 12

dlalmendinger
Participant
Participant

Is there a way simple way, similar to RTOS but the opposite, to go from 2'-1 1/4"  to 25.25

Right now I have to enter FT first, then IN. It works, but if there is a 1 line code that would work, I might go for that.

(defun c:ft ()
(setvar "cmdecho" 0)
(setq   ft (getdist "\nONLY Feet: "  )) ;get Number of Feet
(setq   in (getdist "\nONLY Inches: ")) ;get Number of Inches 
(if (= ft 0) in (+ (* ft 12) in))
)

 

0 Likes
Message 10 of 12

paullimapa
Mentor
Mentor

If you used rtos to convert the real # to string then you can use distof to convert the string back to a real #


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 12

dlalmendinger
Participant
Participant

I will play around with that.

0 Likes
Message 12 of 12

Kent1Cooper
Consultant
Consultant

@dlalmendinger wrote:

I will play around with that.


You just need to enter it in an acceptable way.  Either:

Command: (distof "2'1-1/4")

or

Command: (distof "2'-1 1/4")

returns
25.25

Note in the first one the lack of either a space or a hyphen between the foot mark and the inches number, and the hyphen between the inch number and the fraction.  That's different from the way it's typically displayed [the second one], because in some circumstances in AutoCAD such a thing can't include any spaces.  But within a text string entry like this it works either way.  You could probably come up with some configurations it would not accept, but I assume one of those two would be the likely approach.  [You don't need to include an inch mark in addition to the one that concludes the string.]

Kent Cooper, AIA
0 Likes