Save list of views as images to project using SaveToProjectAsImage method

Hello,

I have a use case that requires saving a list of project views as images to a project rather than exporting them. Saved images are ultimately placed on sheets to show how the project varies with variation in design parameters.

The Revit UI functionality that allows for saving a project view to the project is labeled: “Save to Project as Image…”. Right clicking a view exposes the function as an option available to the user. The images themselves are saved as Family/Type “Rendering/Rendering” in the Revit environment. Please click here for API documentation on the SaveToProjectAsImage method.

Of note, Revit documentation on Rendering an Image (Save the Rendered Image to a File) seems to suggest that internally saved images are compressed jpg files while exported images offer a high quality option. Aside from workflow efficiency it looks like there may be a project file size benefit to saving images internally.

I did manage to follow the method used here by Konrad Sobon to save a single view as an image to a project using the SaveToProjectAsImage method. Hacked Python code is below:

# Copyright(c) 2018, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

try:
    errorReport = None
    
    TransactionManager.Instance.EnsureInTransaction(doc)
    options = ImageExportOptions()
    options.ViewName = "Image_" + doc.ActiveView.Name
    options.ExportRange = ExportRange.CurrentView #API seems to prohibit saving list of views to project as images
    options.ImageResolution = ImageResolution.DPI_150
    options.ZoomType = ZoomFitType.Zoom
    options.Zoom = 100
    result = doc.SaveToProjectAsImage(options)
    #TransactionManager.Instance.TransactionTaskDone()
except:
    # if error occurs anywhere in the process catch it
    import traceback

    errorReport = traceback.format_exc()

# Assign your output to the OUT variable
if None == errorReport:
    OUT = result
else:
    OUT = errorReport

Is there a way to implement the SaveToProjectAsImage method so that a list of views are saved to the project as images?

Thank you for any guidance you may be able to offer.

Best wishes,
Jake

Have a look at the bottom of this post: https://archi-lab.net/image-exporter-for-dynamo/

4 Likes

Hello Konrad,

Thanks for the help and additional input about the limitation of Dynamo when it comes to manipulating the active view. Too bad about that part.

Even so, it’s nice to have the functionality of your node. It saves time and effort when cranking through a bunch of SaveToProjectAsImage work.

Happy New Year,
Jake