# Reference from FamilyInstance

**URL:** <https://forum.dynamobim.com/t/reference-from-familyinstance/31936>\
**Category:** Developers\
**Created:** [February 11, 2019, 7:46am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936 "2019-02-11T07:46:45Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 7:46am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/1 "2019-02-11T07:46:45Z")

</div>

I try create dimension between family instances

how i must get **referenceArray** from familyInstances correctly ?

to be able use:

`doc.Create.NewDimension(view, Line, referenceArray);`

---

<div class="post-metadata">

**Author:** ![lucamanzoni](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/lucamanzoni/32/56718_2.png) [@lucamanzoni](https://forum.dynamobim.com/u/lucamanzoni)\
**Post date:** [February 11, 2019, 8:40am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/2 "2019-02-11T08:40:38Z")

</div>

Hi,  
you need first to create an empty ReferenceArray, it works basically like a list.  
Then you can get the references with many methods, for example with GetReferenceByName

```
ref = ReferenceArray()
   
for x in element:
	a = FamilyInstance.GetReferenceByName(x,"Center (Left/Right)")
	ref.Append(a)

```

Take a look at the RevitAPI to see the available methods:  
[http://www.revitapidocs.com/2018.1/93405c86-ae71-8675-cd74-1ddc271316b6.htm](http://www.revitapidocs.com/2018.1/93405c86-ae71-8675-cd74-1ddc271316b6.htm)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [February 11, 2019, 8:44am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/3 "2019-02-11T08:44:37Z")

</div>

You must construct the ReferenceArray from extracted DB.References within the Family Instance.

You can do this, ncluding options, as displayed here:

> [@Dimension to wall finished face](https://forum.dynamobim.com/t/dimension-to-wall-finished-face/23906/13):
>
> @Ewan_Opie @awilliams Sorry but how would I go about amending this so that it takes a list of lines (3 lines one for each dimension) and 3 lists of elements to be dimensioned? I thought I could create a custom node and just change the lacing but that doesn’t work. How does lacing working with Python nodes within a custom node? Is this possible or is it best to modify the Python itself? Thanks import clr clr.AddReference('RevitAPI') from Autodesk.Revit.DB import \* clr.AddReference('RevitNode…

To extract the DB.References from a Family Instance, refer here for a similar workflow:

> [@Autodesk.Revit.DB.Reference to Curve](https://forum.dynamobim.com/t/autodesk-revit-db-reference-to-curve/26075):
>
> Hello Dynamo people. I want to create Room Boundary Lines at the location of the reference planes from a family. In the family I named the Reference Planes "Front"and “Back”. With Dynamo I can collect these Reference Planes from the family in the project. Last step is to convert these (Autodesk.Revit.DB.Reference) to Curves or Lines, but i downt know how. Can anyone help me? Thanx in advance import clr clr.AddReference(&quot;ProtoGeometry&quot;) from Autodesk.DesignScript.Geom…

I will post a full worked example in the morning. 😀

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 8:51am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/4 "2019-02-11T08:51:22Z")

</div>

> [@lucamanzoni](#):
>
> for x in element:

**element** =\> its list of familyInstances ?

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 8:56am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/5 "2019-02-11T08:56:27Z")

</div>

> [@Ewan\_Opie](#):
>
> I will post a full worked example in the morning.

✌

---

<div class="post-metadata">

**Author:** ![lucamanzoni](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/lucamanzoni/32/56718_2.png) [@lucamanzoni](https://forum.dynamobim.com/u/lucamanzoni)\
**Post date:** [February 11, 2019, 8:57am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/6 "2019-02-11T08:57:45Z")

</div>

Yes, exactly, usually I call element the input

`element = IN[0]`

but _elements_ would be more appropriate 😉

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 9:03am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/7 "2019-02-11T09:03:04Z")

</div>

@lucamanzoni

1.) its not work for me , my be because of current view is ViewSection?

2.)  
Where i can see all list of GetReferenceByName  
“Center (Left/Right)”  
…

---

<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:** [February 11, 2019, 9:18am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/8 "2019-02-11T09:18:43Z")

</div>

A great example in python by @lucamanzoni or @Ewan_Opie will probably be more appropriate if you want to understand how to do it, but if you are in a hurry, there are already custom nodes.

 ![FamilyInstance%20Reference](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/5/e5467f81b0f1003e1a30809eeb6ad1e367b8ba79.png)

---

<div class="post-metadata">

**Author:** ![lucamanzoni](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/lucamanzoni/32/56718_2.png) [@lucamanzoni](https://forum.dynamobim.com/u/lucamanzoni)\
**Post date:** [February 11, 2019, 9:31am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/9 "2019-02-11T09:31:07Z")

</div>

Yes exactly. The page of the RevitAPI, used by @Alban_de_Chasteigner in his great package, is this one:

> **[FamilyInstanceReferenceType Enumeration](https://www.revitapidocs.com/2019/ab424c61-4b80-9dcd-3f9a-7b35fa670edf.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

If you absolutely need to do it with Python, here is a very simple example:

> [@ReferencePlane within Element](https://forum.dynamobim.com/t/referenceplane-within-element/26769/2):
>
> Hi, you can get the reference planes with the method FamilyInstance.GetReferenceByName and indicate which reference you want, in this case I took “Center (Left/Right)”. Apparently the node you are using takes only model lines as reference, so it’s just easier to use doc.Create.NewDimension in Python, it’s basically working in the same way. import clr clr.AddReference('RevitAPI') from Autodesk.Revit.DB import \* from Autodesk.Revit.DB.Structure imp…

We cannot help further if you don’t post your script and see where are the mistakes.

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 9:36am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/10 "2019-02-11T09:36:33Z")

</div>

> [@lucamanzoni](#):
>
> We cannot help further if you don’t post your script and see where are the mistakes.

Onto ViewSection:

```
element = [familyInst1, familyInst2]
ref = ReferenceArray()
   
for x in element:
	a = FamilyInstance.GetReferenceByName(x,"Center (Left/Right)")
	ref.Append(a)

 doc.Create.NewDimension(doc.ActiveView, Line, ref );

```

And next no result and errors)

---

<div class="post-metadata">

**Author:** ![3Pinter](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/3pinter/32/74327_2.png) [@3Pinter](https://forum.dynamobim.com/u/3Pinter)\
**Post date:** [February 11, 2019, 9:47am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/11 "2019-02-11T09:47:43Z")

</div>

Please @til.shviger read the apidocs to see what you will have to do in order to achieve what you want.

For example where did you define  
“doc”  
“Line”

Understanding what you must do **helps a lot**!

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 9:51am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/12 "2019-02-11T09:51:26Z")

</div>

doc = DocumentManager.Current.DB.Document

Line =\> select line exist at model =\> get start end point =\> Line = Line.CreateBound(start/end points)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/b/1b2492e20608cab27a172ad54337147d8e009e00.png)

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 11, 2019, 10:16am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/13 "2019-02-11T10:16:44Z")

</div>

Its full code

```
import System
from System import *
import clr

#-----------
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
#-------------------------

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

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

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

t = Transaction(doc, "t");
t.Start();

familyInst1 = IN[0]
familyInst2=IN[1]
line = IN[2]

element = [familyInst1, familyInst2]
ref = ReferenceArray()
for x in element:
a = FamilyInstance.GetReferenceByName(UnwrapElement(x),"Center (Left/Right)")
ref.Append(a)
dimension = doc.Create.NewDimension(doc.ActiveView, Line.CreateBound(line.Curve.ToRevitType().GetEndPoint(0), line.Curve.ToRevitType().GetEndPoint(1)) , ref );
t.Commit();
OUT= dimension

```

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

---

<div class="post-metadata">

**Author:** ![lucamanzoni](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/lucamanzoni/32/56718_2.png) [@lucamanzoni](https://forum.dynamobim.com/u/lucamanzoni)\
**Post date:** [February 11, 2019, 10:25am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/14 "2019-02-11T10:25:45Z")

</div>

Ok, now it’s better 😉  
So the problems might be:

- Are references _Center (Left/Right)_ existing in the family? If yes, do they have this name or are they in another language?
- Are these references the one you want to use? If yes, are they perpendicular to the Line?

Moreover instead of Line.CreateBound etc… you can simply use as input:

`line = UnwrapElement(IN[1]).GeometryCurve`

(check the link I previously posted)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [February 11, 2019, 9:23pm UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/15 "2019-02-11T21:23:24Z")

</div>

Your latest error may be the result of incorrect DB.Reference pairing.  
Please refer to the example below:

![image](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/3X/b/8/b8c194e3d7bca35e948d4ba6ffe60d4fab50acf4.png)

![image](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/3X/d/b/db10c5c22b123d3a31538630aec4c6d3105ca5ff.png)

**Python 1**

```
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

def tolist(obj1):
	if hasattr(obj1,' __iter__'): return obj1
	else: return [obj1]
	
FamilyInst = tolist(UnwrapElement(IN[0]))
RefName = IN[1]
FamRefs = []

for f in FamilyInst:
	FamRefName = FamilyInstance.GetReferenceByName(f, RefName)
	FamRefs.append(FamRefName)

OUT = FamRefs

```

**Python 2**

```
import clr

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

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

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

def tolist(obj1):
    if hasattr(obj1,' __iter__'): return obj1
    else: return [obj1]

view = doc.ActiveView
dimLines = tolist(UnwrapElement(IN[0]))
RefsToDim = tolist(UnwrapElement(IN[1]))

refArrays = []

outList = []

for refList in RefsToDim:
    rArr = ReferenceArray()
    for r in refList:
        rArr.Append(r)
    refArrays.append(rArr)

TransactionManager.Instance.EnsureInTransaction(doc)
for l,r in zip(dimLines,refArrays):
    try:
        outList.append(doc.Create.NewDimension(view,l.GeometryCurve,r))
    except Exception,e:
        outList.append(e.message)
    
TransactionManager.Instance.TransactionTaskDone()

OUT = outList

```

Hope that helps 😀 #share  
[Multi DB Reference Extraction for Dimension Creation.dyn](https://forum.dynamobim.com/uploads/short-url/qOWOzbX1E6BETef7OSU2KuI4osj.dyn) (11.4 KB)  
_(Dynamo 1.3.4)_

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 12, 2019, 10:20am UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/16 "2019-02-12T10:20:46Z")

</div>

@Ewan_Opie Thank you for your support ! I will try it !

What category elements do you used?

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [February 12, 2019, 5:46pm UTC](https://forum.dynamobim.com/t/reference-from-familyinstance/31936/17 "2019-02-12T17:46:42Z")

</div>

The elements shown in my example are structural columns. Let me know how you get on. 😀
