Reference from FamilyInstance

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);

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

4 Likes

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

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

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

I will post a full worked example in the morning. :grinning:

3 Likes

element => its list of familyInstances ?

:v:

Yes, exactly, usually I call element the input

element = IN[0]

but elements would be more appropriate :wink:

@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)”
…

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.

5 Likes

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

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

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

2 Likes

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)

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!

doc = DocumentManager.Current.DB.Document

Line => select line exist at model => get start end point => Line = Line.CreateBound(start/end points)
image

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

Ok, now it’s better :wink:
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)

2 Likes

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

image

image

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 :grinning: #share
Multi DB Reference Extraction for Dimension Creation.dyn (11.4 KB)
(Dynamo 1.3.4)

5 Likes

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

What category elements do you used?

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