# Create Dimension Programmatically

**URL:** <https://forum.dynamobim.com/t/create-dimension-programmatically/37085>\
**Category:** Developers\
**Tags:** revit, python, geometry, dynamo\
**Created:** [June 13, 2019, 3:14am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085 "2019-06-13T03:14:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshial](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jshial/32/91559_2.png) [@jshial](https://forum.dynamobim.com/u/jshial)\
**Post date:** [June 13, 2019, 3:14am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085/1 "2019-06-13T03:14:32Z")

</div>

Hi community,

I have been working on creating linear dimension between some family instances while some problems baffles me a lot.

## **I have the sample Revit file and dynamo file with more detailed comments uploaded at the bottom, 👇**

Latest problem: Invalid number of references.

What I am trying to do is creating a linear dimension between the left edges on two boxes (1st and 4th) in a section view.

Like this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/a/daf410b9c6d6495ba968d7c78a07cbb6915dfb6e.png)

What I have accomplished is create the dimension by referencing two detail lines drawn on the boxes.

Using method: NewDimension(view, line, referenceArray)

I sketched a model line on the wall serving as the second argument for the method.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/5/656fd7da1f1541c80221b7651bb4cc21b251a3f3.png)

Code in Python node:

```
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel = uidoc.Selection

col = FilteredElementCollector(doc)

#Preparing input from dynamo to revit
c_1 = UnwrapElement(IN[0]).GeometryCurve
c_2 = UnwrapElement(IN[1]).GeometryCurve
direction_curve = UnwrapElement(IN[2]).GeometryCurve

ref_array = ReferenceArray()
ref_array.Append(c_1.GetEndPointReference(0))
ref_array.Append(c_2.GetEndPointReference(0))

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

doc.Create.NewDimension(doc.ActiveView, direction_curve, ref_array)

TransactionManager.Instance.TransactionTaskDone()

OUT = 0

```

Creation succeed:

From:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/3/038d3a32a985c765c69ea7a9ea77522482ecea90.png)

To:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/6/06612726532825209f290d245ab4fc645645f8ad.png)

But I really want to use the native references on the box instead of these detail lines.

So, I tried to retrieve the box geometry specific to the section view, and use one of the lines I have as reference.

```
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel = uidoc.Selection

col = FilteredElementCollector(doc)

#Preparing input from dynamo to revit
elem = UnwrapElement(IN[0])

opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.View = doc.ActiveView

lst = list(elem.get_Geometry(opt))
solid = lst[0]

geo_instance = lst[1]
instance_geo = list(geo_instance.GetInstanceGeometry())

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

TransactionManager.Instance.TransactionTaskDone()

OUT = solid.ToProtoType(), instance_geo[1:]

```

I separate the solid from the lines and convert it to ProtoGeometry just for previewing where the lines are on the box.

Now, left edges obtained.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/b/7bc0c37b1637cd67084131b91c5c4e1a5a9ea3f5.png)

**Creation failed due to:**

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/c/cc58de6c3a0b5717bc77ae3e4f2a564f64556f1a.png)

Line 53, the NewDimension() method, seems these two native references are not valid for creating dimension.

```
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel = uidoc.Selection

col = FilteredElementCollector(doc)

#Preparing input from dynamo to revit
ref_array = ReferenceArray()
ref_array.Append(IN[0].Reference)
ref_array.Append(IN[1].Reference)

direction_line = UnwrapElement(IN[2]).GeometryCurve

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

dimension = doc.Create.NewDimension(doc.ActiveView, direction_line, ref_array)

TransactionManager.Instance.TransactionTaskDone()

OUT = dimension.ToDSType(True)

```

Really appreciate ur help!🙂

Family & Dynamo Script & Revit File

> **[Box.rfa](https://drive.google.com/file/d/1fnM-zSTy7KDrBWGktbyzlGSBkjUfIrrM/view?usp=sharing)**
>
> Google Drive file.

  

> **[QueryReferencesInFamily.dyn](https://drive.google.com/file/d/1cEcZar_PWGkks5YLP4ag2K7aJOubI6IN/view?usp=sharing)**
>
> Google Drive file.

  

> **[Dimension Test.rvt](https://drive.google.com/file/d/1mZm80nr2tvS0KPm4pB2IiGB3VZxEUOAF/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![Dmytro\_Serebriian](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dmytro_serebriian/32/75575_2.png) [@Dmytro\_Serebriian](https://forum.dynamobim.com/u/Dmytro_Serebriian)\
**Post date:** [June 13, 2019, 11:14am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085/2 "2019-06-13T11:14:17Z")

</div>

Hi, you need to get reference planes in your family  
Use for example FamilyInstance.GetReferences(element, FamilyInstanceReferenceType.Left)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/f/5f43271014435ffa19db68b29b29eec839e2d6a2.png)

Here you can find all reference types [https://www.revitapidocs.com/2018/ab424c61-4b80-9dcd-3f9a-7b35fa670edf.htm](https://www.revitapidocs.com/2018/ab424c61-4b80-9dcd-3f9a-7b35fa670edf.htm)

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [June 13, 2019, 11:45am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085/3 "2019-06-13T11:45:47Z")

</div>

Hi @jshial,

Maybe not the answer you’re waiting for, but it’s easier using a package.

 ![QueryReferencesInFamily](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/f/4fdb1fe66dd5209f6f54d1b91c0fe750a48c7970.png)  
 ![QueryReferencesInFamily%202](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/d/9d9a791799fa01e0ba13f38c66b5fca457cf2914.png)

---

<div class="post-metadata">

**Author:** ![jshial](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jshial/32/91559_2.png) [@jshial](https://forum.dynamobim.com/u/jshial)\
**Post date:** [June 14, 2019, 10:07am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085/4 "2019-06-14T10:07:22Z")

</div>

Works like a charm! Thx!

---

<div class="post-metadata">

**Author:** ![jshial](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jshial/32/91559_2.png) [@jshial](https://forum.dynamobim.com/u/jshial)\
**Post date:** [June 14, 2019, 10:08am UTC](https://forum.dynamobim.com/t/create-dimension-programmatically/37085/5 "2019-06-14T10:08:36Z")

</div>

Thx, helpful as always!
