> For the complete documentation index, see [llms.txt](https://dynamopythonprimer.gitbook.io/dynamo-python-primer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dynamopythonprimer.gitbook.io/dynamo-python-primer/4-revit-specific-topics/working-with-units.md).

# 4.11 Working With Units

#### How Revit Measures Lengths

When retrieving any length value using Revit's API, it will automatically be returned in decimal feet (for example, 6 inches = 0.5 Feet). Displaying lengths in any commonly-used format will require special conversion methods. In the example below, we feed a 5,000mm line into the Python Script node:

```python
#Boilerplate Code

detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
OUT = decimal_feet_length
```

The above code returns a value of 16.404, which is the same length but measured decimal feet.

#### Converting Between Units

Decimal feet isn't very useful to anyone so you'll want to convert to something more helpful. To make this conversion, we'll want to use Revit's [UnitUtils](https://apidocs.co/apps/revit/2019/128dd879-fea8-5d7b-1eb2-d64f87753990.htm) class. Furthermore, we'll be restricted to choosing value types from Revit's [DisplayUnitType](https://apidocs.co/apps/revit/2019/7d3d3306-a4c2-c577-0aeb-cca42d6cfd2f.htm) enumeration. Let's see this in action:

For Revit version 2021 or lower

```python
#Boilerplate Code

detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
metric_length = UnitUtils.Convert(decimal_feet_length, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS)
OUT = metric_length
```

For Revit version 2021 or higher

```py

detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
metric_length = Autodesk.Revit.DB.UnitUtils.Convert(decimal_feet_length, UnitTypeId.Feet, UnitTypeId.Millimeters)
OUT = metric_length

```

#### Bonus: Converting Rotations

Sometimes when passing an angle value in to the Revit API, it needs to be converted from degrees to radians first. This can also be done using UnitUtils.Convert(), like so:

For Revit version 2021 or lower

```python
#Boilerplate Code

angle = 90.0
radians_equivalent = UnitUtils.Convert(angle, DisplayUnitType.DUT_DECIMAL_DEGREES, DisplayUnitType.DUT_RADIANS)
OUT = radians_equivalent
```

For Revit version 2021 or higher

```py
#Boilerplate Code

angle = 90.0
radians_equivalent = UnitUtils.Convert(angle, UnitTypeId.Degrees, UnitTypeId.Radians)
OUT = radians_equivalent
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dynamopythonprimer.gitbook.io/dynamo-python-primer/4-revit-specific-topics/working-with-units.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
