Hey all -
While working on a project I came upon the need to do some unit conversion within GH, so I decided to write a script to handle this. I've attached it as a user object. It takes two strings, defining the input and output unit systems, in the form of "mm" or "in^2" or "yd^3" etc. It will then output the necessary conversion factor. It also optionally accepts a list of values, and will convert them for you if they are present.
A word of caution: I have not tested this thoroughly, so it may produce some weird results - but so far it seems to work for me. If you catch a bug, please let me know! Also, please pay attention to the "out" stream - it will alert you to an error if there is a problem with your input. Even if there are errors, the component will produce numerical output, so if you blindly trust the results without checking the error output you may be working with erroneous values.
Finally, if you take a look at the code, please don't judge too harshly! I am an entirely self-taught programmer, so I am sure my code is inefficient and messy and misses a lot of best practices. If you do see something that could be improved upon, let me know; I am always eager to learn.
Download it here: Unit%20Conversion.ghuser (or here: UnitConversion.gh)
cross posted at my blog: http://heumanndesigntech.wordpress.com
Ángel Linares
Thanks for the tool!...I hope some day everybody forgets their traditions and the units system become universal...
Humanity have lost important effort and money using international and imperial units system in the same works (spaceship lost, time in architectural projects...).
Aug 7, 2011
Arthur Mamou-Mani
Hi Andrew, Thanks so much for this very helpful tool which would deserve a plugin ! I changed the extension to ghx and opened it with GH 0050 but got the following error:
Aug 8, 2011
Danny Boyes
@Arthur, I would say it's not the Anglo-Saxons holding the metric system back. As you can see from the image below its Liberia in West Africa.
Countries by date of metrication. Colours red to green show the pattern of metrication from 1795 to 1998. Black identifies countries that have not adopted the metric system as the primary measurement system. White identifies countries that already used the metric system at the time they gained their independence.
Aug 8, 2011
Arthur Mamou-Mani
Danny you're so very English blaming Liberia ;)
I think the expression "Imperial Unit" says it all !
Aug 8, 2011
Danny Boyes
Aug 8, 2011
Andrew Heumann
Aug 8, 2011
Arthur Mamou-Mani
Thanks Andrew,
It's the first time I hear about a .ghuser file! It's great thoguh, how did you save it as such?
The unit conversion script is a very political one ! A little English/French flag might be necessary as logo :) http://www.youtube.com/watch?v=9V7zbWNznbs
Could you post a print screen of how to use it?
Cheers,
Arthur
Aug 8, 2011
Andrew Heumann
Hey Arthur -
Here are some images of the unit conversion script in action:
Aug 8, 2011