Export and Import Family Type Images in the Family Editor

Wanted to share this graph that is able to export an image of each Type in the Family Editor to a folder and then set the exported image to the Type Image for the same type.

  1. Pick a Folder to Export the Images
  2. Make sure all of the types have the correct parameter settings.
  3. Run!

Python:

#Sean Page, 2023
import clr
import os

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
results = []

types = doc.FamilyManager.Types
grp = TransactionGroup(doc)
grp.Start("Export Views")
for type in types:
	t = Transaction(doc)
	t.Start("Export Type")
	doc.FamilyManager.CurrentType = type
	t.Commit()
	opts = ImageExportOptions()
	opts.ExportRange = ExportRange.CurrentView
	opts.HLRandWFViewsFileType = ImageFileType.PNG
	opts.ShadowViewsFileType = ImageFileType.PNG
	opts.FitDirection = FitDirectionType.Vertical
	opts.ZoomType = ZoomFitType.Zoom
	opts.PixelSize = 400
	opts.ImageResolution = ImageResolution.DPI_150
	opts.FilePath = os.path.join(IN[0],type.Name)
	results.append(type.Name)
	doc.ExportImage(opts)
	t = Transaction(doc)
	t.Start("add image")
	for param in doc.FamilyManager.Parameters:
		if param.Definition.Name == "Type Image":
			#MessageBox.Show(opts.FilePath);
			imgOpts = ImageTypeOptions(opts.FilePath +".png",False,ImageTypeSource.Import)
			img = ImageType.Create(doc, imgOpts)
			doc.FamilyManager.Set(param, img.Id)
			break
	t.Commit();
grp.Assimilate();

OUT = results

Export Type Images.dyn (5.7 KB)

5 Likes

Hello. Thanks for sharing this script. The name of the file is the name of the type (80 x 210 cm.png) but,… How can the name of the family be added to the name? (Puerta de 1 hoja-80 x 210 cm.png). Thanks. Regards

1 Like

Yes, we can use the Title property of the Document to append the Family name, assuming it has been saved at least one time.