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.
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
thanks very interesting. I am wondering how to do the reverse, there is a family type parameter builtin called Type Image where there is an image loaded in the parameter of the family, I want to extract it to a folder instead of inserting (setting) it in the parameter type Image.
So, this gets a little harder to do, but here is a way to start:
#Sean Page, 2024
import clr
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.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
if isinstance(IN[0], list):
element = UnwrapElement(IN[0])
else:
element = [UnwrapElement(IN[0])]
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
results = []
#Get all Family Parameters
params = doc.FamilyManager.Parameters
#Iterate Parameters
for param in params:
#Images are stored as ElementId
if param.StorageType == StorageType.ElementId:
#Get the element from the parameter
elem = doc.GetElement(doc.FamilyManager.CurrentType.AsElementId(param))
#Check to see if the element category is Raster Image
if elem.Category.BuiltInCategory == BuiltInCategory.OST_RasterImages:
#use the GetImage method to return the bitmap
results.append(elem.GetImage())
TransactionManager.Instance.TransactionTaskDone()
OUT = results
import clr
# Add reference to System.Drawing for image manipulation
clr.AddReference("System.Drawing")
from System.Drawing import Image
from System.Drawing.Imaging import ImageFormat
import System
# Directory to save images
outputDir = "C:\\path\\to\\save\\images"
if not System.IO.Directory.Exists(outputDir):
System.IO.Directory.CreateDirectory(outputDir)
# Assuming `results` contains System.Drawing.Bitmap objects
for idx, bitmap in enumerate(results):
# Construct a file path using str.format method
filePath = System.IO.Path.Combine(outputDir, "image_{0}.png".format(idx))
# Save the bitmap to file
bitmap.Save(filePath, ImageFormat.Png)
Here is what’s inside the python just to sequence the image names for saving.
#Sean Page, 2024
import clr
clr.AddReference('System')
from System.Collections.Generic import List
path = IN[0]
rng = IN[1]
OUT = [path + " " + str(i)+".png" for i in range(len(rng))]