Revit Family Type Image Export

Hi friends,

I am attempting to use Dynamo to take a Revit family and export an image of the family geometry for every family type within the family. In my example below, I have taken the ootb desk family and am trying to create thumbnails of the desk:

import clr

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

clr.AddReference(‘System’)
from System.Collections.Generic import List

clr.AddReference(“System.Drawing”)
from System.Drawing import Size

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])

images =
size = Size(100,100)
for e in elements:
images.Add(e.GetPreviewImage(size))

OUT = images

The method leverages the ElementType.GetPreviewImage (credit to @SeanP for this solution) but the preview doesn’t update to reflect the physical change in geometry per family type.

This led me to directly opening the family document and view the current family type:

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

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
if doc.IsFamilyDocument:
OUT = doc.FamilyManager.CurrentType
else: OUT = None

My thought is that I might be able to use the CurrentType property and change the current type using this:

image

Going this route, I think I need to add a Loop function but I am stumped on how to set a new current type, export the view, then cycle to the next type to set as current and export…

I’ll circle back tomorrow with an update on progress, but if there is any other forum posts or nodes that you might be aware of that can help address this challenge I would warmly accept your assistance. Thanks!

-Anthony

I am not sure you will be able to do this as you expect. The GetPreviewImage needs to be used on a FamilyType, but that is the Type of a Family Instance, not the FamilyType inside the Family Editor. Also, the PreviewImage in a project only gives you the last type used, which is what I am sure you are seeing.

You may be able to use something like this blog post and export images from each view, but not sure it will get you want you want.
The Building Coder: Exporting Image and Setting a Default 3D View Orientation (typepad.com)

Also, here is a quick snippet to get each type / set current type:

import clr

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

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

clr.AddReference("System.Drawing")
from System.Drawing import Size

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

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

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
element = UnwrapElement(IN[0])

size = Size(100,100)

images = []
famdocs = []
types = []
famdocs = doc.EditFamily(element.Family)
t = Transaction(famdocs)
t.Start("yes")
for type in famdocs.FamilyManager.Types:
	cType = famdocs.FamilyManager.CurrentType = type
	types.append(cType.GetType())
	#images.append(cType.GetPreviewImage(size))
t.RollBack()
famdocs.Close(False)

OUT = types

1 Like

Hello
the preview image of a family is defined by default with the last active type that the user selected (does not work with the CurrentType property)
Currently the only way I know of is to split each type of family into a new family (nested or not) and then load them individually into a project to get the preview image.

3 Likes

Thanks for the valuable feedback SeanP and c.poupin! After considering your comments and doing additional testing, I decided to go back to the drawing board and take a different (maybe more conventional?) approach to solving the challenge.

I load the family into a Revit project, insert instances of every family type, create 3D views of each instance, isolate the geometry using Clockwork’s View.PermanentlyIsolateElement and export image by view:

4 Likes