# Autodesk.Revit.DB.UnitType.UT\_Length

**URL:** <https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664>\
**Category:** Uncategorized\
**Created:** [May 16, 2023, 1:19pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664 "2023-05-16T13:19:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgeorge](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dgeorge](https://forum.dynamobim.com/u/dgeorge)\
**Post date:** [May 16, 2023, 1:19pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664/1 "2023-05-16T13:19:38Z")

</div>

Hi!

Just a noob question 🙂  
I’m in trouble with those lines of code from a script written by [learndynamo.com](http://learndynamo.com)

```auto

getDocUnits = doc.GetUnits()
getDisplayUnits = getDocUnits.GetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length).DisplayUnits

```

Does anybody know how to solve this? I’m working on Revit 2023.

Thanks!

---

<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:** [May 16, 2023, 2:45pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664/2 "2023-05-16T14:45:46Z")

</div>

UnitType is no more. It was replaced with ForgeTypeId.  
Use GetSpecTypeId()  
[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:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 16, 2023, 8:04pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664/3 "2023-05-16T20:04:31Z")

</div>

Hi @dgeorge  
here an example

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/4/843f23280ecb4db2a2a8ea6464a1a97d523d8477.png)

```auto
import sys
import clr

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

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

#Get Important vars
doc = DocumentManager.Instance.CurrentDBDocument

UIunit = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
nameUnit = LabelUtils.GetLabelForUnit(UIunit)

OUT = nameUnit, UIunit.TypeId

```

---

<div class="post-metadata">

**Author:** ![dgeorge](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dgeorge](https://forum.dynamobim.com/u/dgeorge)\
**Post date:** [May 16, 2023, 10:17pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664/4 "2023-05-16T22:17:43Z")

</div>

Thanks so much! The script just ran fine over those lines 🙂  
I have another error, at line 34… I probably missed something:

```auto

import sys
import clr

#import Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
curves = IN[0]
views = UnwrapElement(IN[1])
heights = IN[2]
output = []
doc = DocumentManager.Instance.CurrentDBDocument

getDocUnits = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
getDisplayUnits = LabelUtils.GetLabelForUnit(getDocUnits)

for curveList, viewList, height in zip(curves, views, heights):

	**height = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(height, getDisplayUnits )**
	
	tempList = []
	for curve, view in zip(curveList,viewList):
		
		viewCropManager = view.GetCropRegionShapeManager()		
		cLoop = viewCropManager.GetCropShape()[0]
		cLoopCurves = [x.ToProtoType() for x in cLoop]
		
		PointA = cLoopCurves[3].EndPoint
		PointD = cLoopCurves[3].StartPoint
		curveMP = Curve.PointAtParameter(curve, 0.5)

		if Geometry.DistanceTo(curveMP,curve.EndPoint) < Geometry.DistanceTo(curveMP, PointA):
			PointA = curve.EndPoint		
			
		if Geometry.DistanceTo(curveMP,curve.StartPoint) < Geometry.DistanceTo(curveMP, PointD):
			PointD = curve.StartPoint			
		
		PointB = Point.ByCoordinates(PointA.X, PointA.Y, PointA.Z + height)
		PointC = Point.ByCoordinates(PointD.X, PointD.Y, PointD.Z + height)
			
		LineA = Line.ByStartPointEndPoint(PointA,PointB).ToRevitType()
		LineB = Line.ByStartPointEndPoint(PointB,PointC).ToRevitType()
		LineC = Line.ByStartPointEndPoint(PointC,PointD).ToRevitType()
		LineD = Line.ByStartPointEndPoint(PointD,PointA).ToRevitType()
		
		curveLoop = Autodesk.Revit.DB.CurveLoop.Create([LineA, LineB, LineC, LineD])

		TransactionManager.Instance.EnsureInTransaction(doc)		
		viewCropManager.SetCropShape(curveLoop)
		TransactionManager.Instance.TransactionTaskDone()
		
		tempList.append(view.ToDSType(False))

	output.append(tempList)
#Assign your output to the OUT variable.
OUT[0] = output
OUT[1] = nameUnit
OUT [2] = UIunit.TypeId

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 17, 2023, 9:32pm UTC](https://forum.dynamobim.com/t/autodesk-revit-db-unittype-ut-length/89664/5 "2023-05-17T21:32:36Z")

</div>

try to replace

`height = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(height, getDisplayUnits )`

by

`height = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(height, getDocUnits )`

and

```auto
OUT[0] = output
OUT[1] = nameUnit
OUT [2] = UIunit.TypeId

```

by

`OUT = output, nameUnit, UIunit.TypeId`
