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.
- Pick a Folder to Export the Images
- Make sure all of the types have the correct parameter settings.
- 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)