Creating Dimensions in families

Hello everyone,

I’m trying to create dimensions in a Revit family file. The build-in node, Dimension.ByElements, doesn’t allow me to do this since this is programmed only to work in project documents. I attempted to write my own script, but I’m not very well aquainted with python.

Bellow is the script i’ve written myself:

import clr
from System.Collections.Generic import *

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True


    
items = UnwrapElement(IN[0])
lines = IN[1]
view = UnwrapElement(IN[2])

references = ReferenceArray()
for reference in items
	references.Append(reference.Reference())



TransactionManager.Instance.EnsureInTransaction(doc)

for line in lines:
	try:
		createddimension = doc.FamilyCreate.NewDimension(doc.ActiveView, line.ToRevitType(), references)
		message = "Succes" 
	except:
		message = "failed"

TransactionManager.Instance.TransactionTaskDone()

OUT = [message]

I believe it must be possible since I found this example written in C#

https://jeremytammik.github.io/tbc/a/0539_dim_walls_it_face.htm