Author Topic: metric/imperial conversion at command line input  (Read 5990 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
metric/imperial conversion at command line input
« on: August 31, 2009, 07:56:55 PM »
Hi All,

I know I can probably work this out by typing out the routine as needed but it would be very long winded and complex for each input (and my lisp skills are limited to things like (/ 124 2) at the command input when needed :) ).

What I would like to do is convert imperial lengths to metric on the fly, for eg. say I want to draw a line from some point to 12' 6 3/4" to the right but I'm using metric units.

I was thinking along the lines of as lisp routine I can use like this:

LINE
Specify first point: (I pick the point)
Specify next point: (convert 12' 6 3/4")  <<--- this or similar

The reason we need something like this is all our 'new' work on old structures is metric but a lot of our existing structures we add to or repair are detailed in imperial. This would save a great deal of time with a calculator doing the conversions.
I have written a conversion app in C# but it is still double handling.

any help or clues would be great, thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: metric/imperial conversion at command line input
« Reply #1 on: August 31, 2009, 08:10:18 PM »
I think you can simplify this a bit by first
changing the Units, then have the input number multiplied (12x)metric value
then when you switch the units back the dimension will be correct
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Spike Wilbury

  • Guest
Re: metric/imperial conversion at command line input
« Reply #2 on: August 31, 2009, 08:35:05 PM »
Mick,

If I understood, you can use:

(setq d (GetDist "\nDistance: ")) ;; and don't worried about the current units
Command: Distance: 12'6-3/4
Command: 150.75

Command: !d
Command: 150.75

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #3 on: August 31, 2009, 09:06:00 PM »
Thanks gent's.

Luis, that doesn't quite work for me - "Requires numeric distance or 2 points"
my units are set to metric and I pick first point and entrer the imperial measure as above for the second.

I'm sure it can be done, Inventor does this as standard which is very handy.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8805
  • AKA Daniel
Re: metric/imperial conversion at command line input
« Reply #4 on: August 31, 2009, 09:17:02 PM »
Just draw everything in metric units (scale the old stuff * 24.5) and  setup dimension your styles

BTW, I had written commands called IO, (imperial offset), IL (imperial line) ,IC, etc that would still draw/change the entity(s) in metric units but you could enter the dimensions as imperial, really handy for working of imperial prints

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8805
  • AKA Daniel
Re: metric/imperial conversion at command line input
« Reply #5 on: August 31, 2009, 09:31:24 PM »
Bwahahaha I think this was the sencond lisp routine I had ever written  :-D




Code: [Select]
; Written by Daniel Marcotte and may not be used by any
; entity without Imperial authorization
(defun c:ic (/ sum num rord pt1)     
  (setq rOrd (getstring "Enter Diameter or Radius R/D: "))
  (setq PT1 (getpoint "\nPick Start Point"))
  (if (= rord "d")
    (command "circle" pt1 "d")
    (command "circle" pt1)
  ) 
  (setq num (getreal "\nEnter your Imperial Dimension: "))
  (setq sum (* num 25.4))
  (command sum)
  (princ)
)

Spike Wilbury

  • Guest
Re: metric/imperial conversion at command line input
« Reply #6 on: August 31, 2009, 09:54:27 PM »
Mick,

Have a look at this one:

(defun c:IM()
  (setq ds (getstring t "\nDistance: "))
  (distof ds 4))

Command: l
LINE Specify first point:
Specify next point or [Undo]: 'im

Distance: 12'4
148.0

Specify next point or [Undo]:

It works here.

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #7 on: August 31, 2009, 09:56:02 PM »
Just draw everything in metric units (scale the old stuff * 24.5) and  setup dimension your styles

BTW, I had written commands called IO, (imperial offset), IL (imperial line) ,IC, etc that would still draw/change the entity(s) in metric units but you could enter the dimensions as imperial, really handy for working of imperial prints


This is what we're after, all of our work is off imperial prints.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #8 on: August 31, 2009, 09:57:16 PM »
Thanks Luis, I'll take a look, I will need to multiply that by 25.4 to get mm though, thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Spike Wilbury

  • Guest
Re: metric/imperial conversion at command line input
« Reply #9 on: August 31, 2009, 10:02:52 PM »
Thanks Luis, I'll take a look, I will need to multiply that by 25.4 to get mm though, thanks.

(defun c:IM()
  (setq ds (getstring t "\nDistance: "))
  (cvunit (distof ds 4) "inch" "mm"))

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #10 on: August 31, 2009, 10:12:49 PM »
Awesome Luis, almost there (I did see the cvunit in the help, I need to look up distof ds 4 now ;))

The only problem is it turns off 'polar', ortho works ok though so I might be able to work around this, thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Spike Wilbury

  • Guest
Re: metric/imperial conversion at command line input
« Reply #11 on: August 31, 2009, 10:22:21 PM »
Awesome Luis, almost there (I did see the cvunit in the help, I need to look up distof ds 4 now ;))

The only problem is it turns off 'polar', ortho works ok though so I might be able to work around this, thanks.

polar tracking?.... never had use that... let me check...

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8805
  • AKA Daniel
Re: metric/imperial conversion at command line input
« Reply #12 on: August 31, 2009, 10:32:58 PM »

.... all of our work is off imperial prints.

Yep I did that for many years, what I ended up doing is writing a little floating toolbar that would paste the conversion @ any command

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #13 on: August 31, 2009, 10:44:33 PM »
Ahh, nice one!

The code Luis posted works fine, just have to work out how to toggle polar back on when the line/circle etc. are completed.
This is what I have so far which doesn't work as expected -

Code: [Select]
;; Imperial string to mm converter
(defun c:IMP()
  ;save the currnet polar mode [if used we can set it back]
  (setq polmode (getvar "polarmode"))
  ;set orthomode on
  (setvar "orthomode" 1)
  (setq ds (getstring t "\nEnter Imperial Distance: "))
  (cvunit (distof ds 4) "inch" "mm")
;this is where it falls down -
  (setvar "orthomode" 0)
  (setvar "polarmode" polmode)
 )
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3653
  • (x-in)->[process]->(y-out) ... simples!
Re: metric/imperial conversion at command line input
« Reply #14 on: August 31, 2009, 10:46:23 PM »
That's right, if I remember correctly lisp prints the result of the last function to the command line, how do I get it to send it to the command line once calculated but before it resets the modes??
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien