Reload All Images?

Hoping that maybe this is possible using dynamo + python (or any combo really). I have a project where there is roughly 10 or so images imported into the Revit file as background information for an as-built condition. Occasionally there is a need to reload these images (ie. someone modifies the image to be better read, brightness/contrast etc). It’s a a bit cumbersome to reload each of these 10 images manually one at a time.

I found this thread;
http://dynamobim.org/forums/topic/is-it-possible/

Where there was a reload portion but that reload portion specified a specific file path and reloaded 1 file. Is is possible to specify a specific folder and have Dynamo/Python reload all images at that folder?

Thanks!

Hello Chris!
I added some loops to the code in the thread you linked to. Looks like it’s working, but you have to click on a couple of images before the changes are reflected in Revit. I tried to add doc.Regenerate() to the end, but it had no effect.

    #Modification of code from http://archi-lab.net/image-management-with-dynamo/
    import clr
    clr.AddReference('RevitAPI')
    from Autodesk.Revit.DB import *

    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

    #Converting input from Dynamo to Revit
    filePaths = IN[0]

    #Isolating filenames
    fileNames = []
    for path in filePaths:
    	tempName = path.split('\\')
    	fileNames.append(tempName[len(tempName)-1])

    #Selecting images
    imgs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RasterImages).WhereElementIsElementType().ToElements()

    reloadedFiles = []

    #Reload images in a transaction
    TransactionManager.Instance.EnsureInTransaction(doc)

    for fileName in fileNames:
    	for i in imgs:
    		imageName = i.ToDSType(True).Name
    		if  imageName == fileName:
    			i.Reload()
    			reloadedFiles.append(imageName)

    TransactionManager.Instance.TransactionTaskDone()

    OUT = reloadedFiles
4 Likes

Wow!! thanks works like a charm and helps me looking at the code to understand what I was missing in my own failed attempts.

Thanks again!

Well it was working well until I used a network location (enabled worksets) and then it went to crap lol. (central file is on a network (P Drive)and my local is on my local drive (D Drive))It looks like it is singling out just 1 jpg and i cannot tell why?. I am guessing it is with the split string but since I am a python novice it is got me lost.

Thanks in advance for the help

the node “Directory.Contents” of which package is .??