Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting All Parameter Values from Imperial Units to Metric Units

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
imaliasad
5843 Views, 7 Replies

Converting All Parameter Values from Imperial Units to Metric Units

Following up @jeremytammik solution on converting imperial unit to metric unit here. It's hard for me to figure out which enumeration value of DisplayUnitType to choose for all parameters. Because all parameter may have values in different format i.e mm, V, VA. 

As my background is from software engineering I have very little technical knowledge of AEC industry. Currently, I'm retrieving the properties values in imperial units and I'd like to know, does Revit-API provides any easy way to automatically convert the return value format of any type-parameter to metric units. Because I cannot determine which DisplayUnityType enum I should use to get the value in the right format.  I hope there should be a way to achieve this functionality. Appreciate any help.

 

Thank you

- Ali

7 REPLIES 7
Message 2 of 8
jeremytammik
in reply to: imaliasad

I do not think there is a generic method to convert all imperial units to metric.

 

Basically, Revit uses standard metric SI units for everything except length, which is in feet.

 

This is (almost) the only non-SI unit used.

 

You will probably need to implement a conversion for each unit type you encounter.

 

It is probably quite easy once you understand the basic principles.

 

I looked at The Building Coder category on units:

 

 

Here are the posts that look most useful to me to help answer your question:

 

 

I hope this helps and look forward to hearing how you end up solving this.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 8
imaliasad
in reply to: jeremytammik

Interesting, I was hoping there should be some ways to convert units because in Revit 2017 I can see the values in metrics, I thought Revit may have some generic method to display all units according to project settings.

I'll try to dig more into it, hope will come up with some solution soon. Thanks again @jeremytammik.

 

 

Message 4 of 8
jeremytammik
in reply to: imaliasad

You could parse the unit abbreviation string, determine how many inches, feet, mm, metres, etc. it contains, and multiply by a conversion factor from imperial to metric for each imperial unit encountered. The posts I pointed to above illustrate related ideas. Good luck!



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 8
imaliasad
in reply to: jeremytammik

Update:

 

Thanks for the solution I've used it to write a  UnitConverter  script that converts all imperial units to metric units automatically, here

Please feel free to share it with the community. 

 

Thanks,

 

~ Ali

Message 6 of 8
npmagalhaes
in reply to: imaliasad

Hi,

 

I want to do a simple code to define automatically define metric units to the revit model. I excercies that are im imerial, And I have to manualy convert to metric, I lose 5 minute to do this, so what I want is to automize this. How can I use the unitconvert that you do?

 

 

Message 7 of 8
jeremy_tammik
in reply to: npmagalhaes

The Revit user interface does it automatically for you.

 

If you wish to display Revit database units obtained through the API in some other units, you simply convert them. Normally, you simply modify them by a fixed factor that you can determine by comparing the source and target unit. The Revit API also provides built-in methods to do this for you.

 

The Building Coder has frequently discussed many aspects of this topic:

 

https://thebuildingcoder.typepad.com/blog/units/

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 8 of 8

I wrote a couple of simple macros to easily convert your project units between Imperial and Metric. Works with both project and family documents. Just create a new Macro Module, and paste in the code below:

 

        public void ChangeUnitsToImperial()
        {
            Document doc = this.ActiveUIDocument.Document;
            Document templateDoc = Application.OpenDocumentFile(@"C:\ProgramData\Autodesk\RVT " + this.Application.VersionNumber + @"\Templates\English-Imperial\default.rte");
            using (Transaction ta = new Transaction(doc))
               {
                ta.Start("Change Project Units to Imperial");
                doc.SetUnits(templateDoc.GetUnits());
                ta.Commit();
            }
        }
        public void ChangeUnitsToMetric()
        {
            Document doc = this.ActiveUIDocument.Document;
            Document templateDoc = Application.OpenDocumentFile(@"C:\ProgramData\Autodesk\RVT " + this.Application.VersionNumber + @"\Templates\English\DefaultMetric.rte");
            using (Transaction ta = new Transaction(doc))
               {
                ta.Start("Change Project Units to Metric");
                doc.SetUnits(templateDoc.GetUnits());
                ta.Commit();
            }
        }

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community