Custom Family Type Catalog Exporter

Thanks for circling back around on this. It looks like the default Revit export approach encapsulates values with special characters in double quotes. I will look to refactor the python to include this.

Sean truly appreciate you working to update/upkeep your code. When you say special characters do you mean ° for example? New problem is the insert side the new warning is that the parameter doesn’t exist and ° is coming in as ° in the warning dialog. I was just going to start to look into it now.

Basically any characters that may cause issues like “,” commas or " ’ " apostrophes etc. When you use the standard export from Revit family you would get “something, like it’s tomorrow” where right now this graph would just give you something, like it’s tomorrow and as you know that break its. One way would be to just wrap every value in double quotes to help mitigate that, but probably needs a more complete approach to be scalable.

You can test this with a simple family, make a couple types and a couple parameter. You’ll see if say you have a material with a comma in it, it will now have quotes.

Seat Support.txt (320 Bytes)

Gotcha that makes sense. Not that I recommend putting ",’ in most places to those in my firm just like ‘.’ in file names. (although I do always tell the new guy to name the file “Con” just for fun.) Type Catalogs are great but unforgiving in that import export process

1 Like

side question is this saving as UTF-8 or ANSI when making the TXT? Looks like UTF-8 found if you have parameters named with specials characters a quick file save as with ANSI fixes the issue.

Ok, so here is what I have come up with, and what is still not working just right.

  • I exported a Type Catalog from Revit directly and it was actually encoded as UTF-16LE

  • This export maintained special characters / letter as I expected, but broke for Parameter Names / Values with commas.

  • I refactored to encapsulate either of those values when they had a comma

  • I refactored the write to use the codecs class rather than the stream writer.

  1. This enables us to encode as we want to the UTF-16LE or any other as needed
  2. Problem is that for some reason it is hiding an invisible character at the beginning of the text file that is breaking revit.
  • This can be solved in two ways:
  1. Save As from notepad as ANSI
  2. Delete and replace the very first comma on the first line of the file.

There would probably be a way to open and replace the comma, but my first attempts saved the file back as UTF-8 or something other than what it was so I stopped thinking it may need a completely different approach.

#Sean Page, 2021
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
from System.Text import Encoding
import codecs
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
	#check to see if the parameter name has a comma and encapsulate with double quoates
	if pName.Contains(','):
		pName = '"'+pName+'"'
	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 + '\r\n')
#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 = Element.Name.__get__(elem)
			except:
				#This catches materials specifically that are "<Default>" and don't have a name
				value = String.Empty
		#Check for commas in the value and encapsulate with double quotes as needed
		if value.Contains(','):
			value = '"'+value+'"'
		#Add each value for each parameter
		typeString += ","+value
	#Add all values for each Family Type	
	output.Add(typeString + '\r\n')
outfile = codecs.open(path, 'w', encoding='utf-16-le')
try:
	#Write each line to a txt file while encoding for special characters
	for line in output:
		outfile.write(line)
	outfile.close()
	OUT = output
except:
	outfile.close()
	OUT = "Failed to Write File"

Selected Family Type Catalog_v2.dyn (37.1 KB)

2 Likes

@SeanP I’m really excited to use your routine. I belive it will resolve my problem with the Family Type parameter. But, when I ran it, some node warnings appear. (Check the image) Bellow are listed the error texts:

UI.Listview Data: Error: Custom node definition is not loaded!
UI.FilePath Data: Error: Custom node definition is not loaded!
UI.MultipleInputForm ++: Error: Custom node definition is not loaded!

Code Block: Warning: Get. ValueAtindex operation failed.

Write parameter Values: Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last): File “string>”, line 24, in TypeError: iteration over non-sequence of type NoneType.

Could you help me solve them?
I didn’t find any packcage for the custom nodes.
Thank You!

Most likely you need to install the Data shapes package from the package manager.

1 Like

Thanks!
It worked.

As usual, nice work Sean! I am downloading these to give them a try. Why I didnt find these before is beyond me.

I still can’t believe that we do not have a proper function or addin to help do a selective and custom type catalog export. Joe Sferrarra (Sp?) from the Charlotte Revit Users Group use to have a tool that I used all the time and it worked great. However, he stopped developing it a few years ago. It would be sweet if he or someone who still has it could update it for use in the newer Revit versions. It was that awesome. =)

I appreciate the graph. I will reply if i run into any issues with it. =)

1 Like

You’re welcome @jquarry. I actually did convert it to C# shortly after testing it in Dynamo and integrated it into our company’s toolbar. I believe that in R24 there are some improvements to this, but I have not tried it myself to know for sure.

EDIT:
Joe Sferrazza

1 Like

@SeanP I am assuming I am getting this error due to the fact that Python 2 is out and 3 is in… any idea how i could fix this as is so I can use it?

Thats the addin i was talking about by Joe. =)

Can you show the preview of the nodes before the write node? That error is usually due to a list issue.

Doesn’t look like any other issues that I can tell. No null responses that i can tell

1 Like

Could you please show the preview under the node of at least the two nodes before the write. Need to see the data going in.

Sorry @SeanP , the nodes circled in red have the preview pinned for you… let me know if you need a particular one other to be done as well.

Ok, we are getting there. What is the full error message show here?

It makes me scroll it so here is what I got…=)

image

Also, is this supposed to be the default? I will say, the first time I ran it i ended up seeing the Data Shapes UI where I could select what I wanted to include, however since then that UI does not come up before the errored run report… FYI

1 Like