# Easy to do it manually, but can it be done proramatically?

**URL:** https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799
**Category:** Revit
**Tags:** python, units
**Created:** [October 29, 2021, 2:53pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799 "2021-10-29T14:53:38Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [October 29, 2021, 2:53pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/1 "2021-10-29T14:53:38Z")

</div>

I need to do this ask… Just a little help on how to do it in dynamo? or code block?  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/4/0440dfeb73bb632b8b5ca3e3831613edd9f69706.png)

---

<div class="post-metadata">

### Author: ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)
#### Post date: [October 29, 2021, 3:28pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/2 "2021-10-29T15:28:30Z")

</div>

With the API and Python.  
Don’t know if anyone has made a node for these.

---

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [October 29, 2021, 3:47pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/3 "2021-10-29T15:47:59Z")

</div>

I saw this one… I just need to figure out how to read it…

```auto
import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

if IN[0]:
	TransactionManager.Instance.EnsureInTransaction(doc)
	unit = doc.GetUnits()
	format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS, 0.01)
	unit.SetFormatOptions(UnitType.UT_Length,format)
	doc.SetUnits(unit)
	TransactionManager.Instance.TransactionTaskDone()
	OUT = "length unit changed to millimeter"
else:
	OUT = "Set IN[0] to true!"

```

---

<div class="post-metadata">

### Author: ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)
#### Post date: [October 29, 2021, 3:56pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/4 "2021-10-29T15:56:46Z")

</div>

For future reference, please post code inside preformatted text (`</>`) so that it gets formatted properly.

```auto
1 unit = doc.GetUnits()
2 format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS, 0.01)
3 unit.SetFormatOptions(UnitType.UT_Length,format)
4 doc.SetUnits(unit)

```

1. Get the project units.
2. Get the type of units and rounding.
3. Format the unit type and rounding for the specified unit.
4. Apply the unit formatting back to the project units.

---

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [October 29, 2021, 4:06pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/5 "2021-10-29T16:06:36Z")

</div>

Thanks for the explanation… but is there no 5? Set the “unit symbol” to none…

---

<div class="post-metadata">

### Author: ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)
#### Post date: [October 29, 2021, 4:11pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/6 "2021-10-29T16:11:00Z")

</div>

I was just explaining those lines of the code you posted. In order to change the symbol display you would also have to use the FormatOptions for UnitSymbolType.

[https://www.revitapidocs.com/2020/1058a15c-711c-db20-3f11-c9c6a71f113c.htm](https://www.revitapidocs.com/2020/1058a15c-711c-db20-3f11-c9c6a71f113c.htm)

---

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [October 29, 2021, 4:26pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/7 "2021-10-29T16:26:56Z")

</div>

Awesome, exactly what i need… thank you

---

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [October 29, 2021, 6:52pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/8 "2021-10-29T18:52:07Z")

</div>

so why is it that it worls in R20 but not in R22 ? change in API? ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/d/1d80258c7065222cf286321fe785922e3c02439a.png)

---

<div class="post-metadata">

### Author: ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)
#### Post date: [October 29, 2021, 7:17pm UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/9 "2021-10-29T19:17:14Z")

</div>

Exactly.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/5/85cdc995aef024d1b6769727da4b0e221b448842.png)

Units were transitioned to ForgeTypeIds. This is the new method:  
[https://www.revitapidocs.com/2021.1/64822a98-a253-3300-cdbb-17973687878f.htm](https://www.revitapidocs.com/2021.1/64822a98-a253-3300-cdbb-17973687878f.htm)

---

<div class="post-metadata">

### Author: ![Cesar\_Tolentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cesar_tolentino/32/26477_2.png) [@Cesar\_Tolentino](https://forum.dynamobim.com/u/Cesar_Tolentino)
#### Post date: [November 2, 2021, 1:19am UTC](https://forum.dynamobim.com/t/easy-to-do-it-manually-but-can-it-be-done-proramatically/69799/10 "2021-11-02T01:19:34Z")

</div>

Just to complete this thread… The similar solution was found here.

> [@Python script in Dynamo Graphs not working properly in Revit 2022 (Project Units)](https://forum.dynamobim.com/t/python-script-in-dynamo-graphs-not-working-properly-in-revit-2022-project-units/65297):
>
> Hi, I created a Dynamo graph that modify the project units (imperial or metric) and it doesn’t work anymore with Revit 2022. I saw that there was some modification to the API related to units in Revit 2022. I’m not programmer, I’m just someone that had interest in Dynamo so I don’t really know the terms in the industry. I know that DisplayUnitType was now replaced, but other than that, I don’t know how to make it work… Here’s the part of the graph that now fail. TransactionManager.Instance.En…
