Reload all images from a central file

Aw man I was so excited to try this when I got in but it failed as well. The nice thing it did was find all the jpegs without me pointing to a directory. but then it did not reload them. I did however try to incorporate the other string in to see if that worked and it tried and even opened a D/S interface but once I pushed the interface a list was not generated at the end because of errors along the line.

Keep in mind my images reside on a network drive along with the Central Revit File. My local file is on my local “C” Drive

back to my original the original pst runs fine as long as there is not a (2) after the ImageName so it breaks with this string

	if  imageName == fileName:

because imageName does not = fileName with the added (2)

is there a way to just get it to look for all images by bypassing the imagename = all together

See the script below:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

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

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

doc = DocumentManager.Instance.CurrentDBDocument
imgs = FilteredElementCollector(doc)\
	.OfCategory(BuiltInCategory.OST_RasterImages)\
	.WhereElementIsElementType()

#Reload images in a transaction
failed = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in imgs:
	image_path = i.Path
    # Only reload images with a valid path
	if os.path.exists(image_path):
		i.Reload()
	else:
		failed.append(image_path)

TransactionManager.Instance.TransactionTaskDone()

OUT = failed

As Brendan has suggested, I am using the os module to check if the path stored in the ImageType actually exists and only reloads the image if it does. The error you were getting using my previous script implies that one of the image files has either been deleted or moved and cannot be accessed.

3 Likes

OMG that was it!!! it doesn’t care what the name is it reloads the ones with the correct path. Exactly what I was looking for.

Thank you everyone for helping a poor soul out!!! You helped me from pulling all my hair out lol

1 Like

now my next act to add this into a combo before anyone prints. wish me luck

(Atleast I know there are way smarter than me on this site to help if I get stumped)

do you mind expanding the UI.multipleform error? because the error happens in the form and not the python script after which. and the python script after which is just reloadfrom or reload if there is a changes in path.

Good to see the final solution :slight_smile:

On a side note do look into how to use try and except to narrow down issues with your script then remove them once you have adapted your code for the situations.

Taken from Archi-labs website by Konar K Sobon he shows a way to continue with the code but outputs the actual error message if any via trackback module.

There are way more smarter people than me on this site as well, though a few of them will be at autodesk university :slight_smile:

1 Like