Export family types as text node?

Ok, that is after the SpecType change so yeah the DUT isn’t going to work. I may try to see if I can refactor, but wouldn’t be at least till tomorrow.

I don’t have python available, but here is my C# which should be easy enough to port.

namespace RDGRevit.Commands
{
	[Transaction(TransactionMode.Manual)]
	class FamilyTypeCatalogExport : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Document doc = commandData.Application.ActiveUIDocument.Document;
			List<FamilyParameter> usedParams = new List<FamilyParameter>();
			FamilyParameterSet famParams = doc.FamilyManager.Parameters;
			Units famUnits = doc.GetUnits();
			FormatOptions len = famUnits.GetFormatOptions(SpecTypeId.Length);
			List<string> output = new List<string>();
			SaveFileDialog fsd = new SaveFileDialog
			{
				Filter = "Text File | *.txt",
				DefaultExt = "txt",
				OverwritePrompt = true,
				FileName = doc.Title
			};
			if(fsd.ShowDialog() == DialogResult.OK)
			{
				string path = fsd.FileName;
				FamilyTypeSet famTypes = doc.FamilyManager.Types;

				foreach(FamilyType type in famTypes)
				{
					foreach(FamilyParameter param in famParams)
					{
						if(!param.IsDeterminedByFormula)
						{
							if(type.HasValue(param))
							{
								if(!usedParams.Contains(param))
								{
									usedParams.Add(param);
								}
							}
						}
					}
				}
				string variables = "";
				foreach(FamilyParameter param in usedParams)
				{
					ForgeTypeId pType = param.Definition.GetDataType();
					string pName = param.Definition.Name;

					if(pType == SpecTypeId.Length)
					{
						variables += "," + pName + "##LENGTH##FEET";
					}
					else if(pType == SpecTypeId.Area)
					{
						variables += "," + pName + "##AREA##SQUARE_FEET";
					}
					else if(pType == SpecTypeId.Volume)
					{
						variables += "," + pName + "##VOLUME##CUBIC_FEET";
					}
					else if(pType == SpecTypeId.Slope)
					{
						variables += "," + pName + "##SLOPE##SLOPE_DEGREES";
					}
					else if(pType == SpecTypeId.Angle)
					{
						variables += "," + pName + "##ANGLE##DECIMAL DEGREES";
					}
					else if(pType == SpecTypeId.Currency)
					{
						variables += "," + pName + "##CURRENCY##CURRENCY";
					}
					else
					{
						variables += "," + pName + "##OTHER##";
					}
				}
				output.Add(variables);
				foreach(FamilyType famType in famTypes)
				{
					string typeString = "";
					typeString += famType.Name;
					foreach(FamilyParameter param in usedParams)
					{
						ForgeTypeId pt = param.Definition.GetDataType();
						StorageType storeType = param.StorageType;
						string value = string.Empty;
						if(storeType == StorageType.Double)
						{
							if(pt == SpecTypeId.Angle && famType.AsDouble(param) is double angle)
							{
								value = UnitUtils.ConvertFromInternalUnits(angle, UnitTypeId.Degrees).ToString();
							}
							else if(pt == SpecTypeId.Slope && famType.AsDouble(param) is double slope)
							{
								value = UnitUtils.ConvertFromInternalUnits(slope, UnitTypeId.SlopeDegrees).ToString();
							}
							else
							{
								value = famType.AsDouble(param).ToString();
							}
						}
						else if(storeType == StorageType.Integer)
						{
							value = famType.AsInteger(param).ToString();
						}
						else if(storeType == StorageType.String)
						{
							value = famType.AsString(param);
						}
						else if(storeType == StorageType.ElementId)
						{
							ElementId eId = famType.AsElementId(param);
							if(doc.GetElement(eId) is Element elem)
							{
								value = elem.Name;
							}
						}
						typeString += "," + value;
					}
					output.Add(typeString);
				}
				using(StreamWriter sw = new StreamWriter(path))
				{
					foreach(var line in output)
					{
						sw.WriteLine(line);
					}
				}
			}
			return Result.Succeeded;
		}
	}
}
1 Like