Custom Family Type Catalog Exporter

I have noticed that not all of the Parameters nor parameter values for some of my Families were being exported when using the default Export Family Types feature in Revit. This was mostly true for Family Type Shared Parameters that are used for Labels.

Based on wanting to remedy that, I have worked through and crated a graph that allows you to pick the Parameters to export as well as doing some pre filtering for you such as parameters that don’t have a value or ones that are driven by formula.

Here is the Python node that gathers the parameter information:

#Sean Page, 2020
import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument
params = []
names = []
groups = []

#Iternate each parameter in the Family
for param in doc.FamilyManager.Parameters:
	#If the Parameter if Formula Driven, no need to export it
	if param.Formula == None:
		for type in doc.FamilyManager.Types:
			#Check each type to see if the Parameter has a value, if no Type has a value no need to export
			if type.HasValue(param):
				#Check to see if the list already contains the Parameter because you only need it once
				if not params.Contains(param):
					#Add the parameter and parameter name to the output lists
					params.Add(param)
					names.Add(param.Definition.Name)
					groups.Add(param.Definition.ParameterGroup)

OUT = names,params,groups

Here is the Python for the node that gets the values based on ParameterType and Parameter StorageType.

#Sean Page, 2020
import clr

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

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

clr.AddReference('System')
from System.Collections.Generic import List
from System import *
from System.IO import StreamWriter
doc = DocumentManager.Instance.CurrentDBDocument
#Preparing input from dynamo to revit
path = IN[1]
#units = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits
famParams = IN[0]
output = []
famTypes = doc.FamilyManager.Types
#Set up the first line of the Type Catalog with the headers
variables = "";
for param in famParams:
	pType = param.Definition.ParameterType
	pName = param.Definition.Name
	
	if pType == ParameterType.Length:
		variables += "," + pName + "##LENGTH##FEET"
	elif pType == ParameterType.Area:
		variables += "," + pName + "##AREA##SQUARE_FEET"
	elif pType == ParameterType.Volume:
		variables += "," + pName + "##VOLUME##CUBIC_FEET"
	elif pType == ParameterType.Slope:
		variables += "," + pName + "##SLOPE##SLOPE_DEGREES"
	elif pType == ParameterType.Angle:
		variables += "," + pName + "##ANGLE##DECIMAL DEGREES"
	elif pType == ParameterType.Currency:
		variables += "," + pName + "##CURRENCY##CURRENCY"
	else:
		variables += "," + pName + "##OTHER##"
#Add the headers to the final output
output.Add(variables)
#Iterate each type and get the values for each parameter ased on its Storage Type and Parameter Type
for famType in famTypes:
	typeString = String.Empty
	typeString += famType.Name
	for param in famParams:
		pType = param.Definition.ParameterType
		sType = param.StorageType
		value = String.Empty
		if sType == StorageType.Double:
			if pType == ParameterType.Angle:
				value = UnitUtils.ConvertFromInternalUnits(famType.AsDouble(param),DisplayUnitType.DUT_DECIMAL_DEGREES).ToString()
			elif pType == ParameterType.Slope:
				value = UnitUtils.ConvertFromInternalUnits(famType.AsDouble(param),DisplayUnitType.DUT_SLOPE_DEGREES).ToString()
			else:
				value = famType.AsDouble(param).ToString()
		if sType == StorageType.Integer:
			value = famType.AsInteger(param).ToString()
		if sType == StorageType.String:
			value = famType.AsString(param)
		if sType == StorageType.ElementId:
			eid = famType.AsElementId(param)
			elem = doc.GetElement(eid)
			try:
				value = elem.Name
			except:
				value = elem.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
		#Add each value for each parameter
		typeString += ","+value
	#Add all values for each Family Type	
	output.Add(typeString)
try:
	#Write each line to a txt file
	sw = StreamWriter(path)
	for line in output:
		sw.WriteLine(line)
	sw.Close()
	OUT = output
except:
	OUT = "Failed to Write File"

Selected Family Type Catalog.dyn (40.8 KB)

As always, thanks to @Mostafa_El_Ayoubi for Data-Shapes!

5 Likes