Reload all images from a central file

I was using a previous string

and posted on there for help but have not got any responses. I am trying to get my revit local file to reload all images from a central file location. I used someone else’s script (arch+lab) from this location

http://dynamobim.org/forums/topic/is-it-possible/

the script worked fine for a local file, but once I made it a central file(network path), I cant reload the images from a local file (local path)

so my fix was to add in the /W Document.CentralPath to the string and now it only reloads one image file (and it is not the first image (its line 12 from the directory list) For some reason I think the IP address for the directory path is messing it up in the code string.

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

I am stumped and any help would be greatly appreciated.

Thanks in advance

Would you be able to provide a sample file to use as a test case? I’ve tried to use the code snippet you’ve provided along with filepaths in a similar format and do not seem to be having any issues up to that point.

Image Reload All.dyn (16.7 KB)

looks like it is in the output code not the other. once I removed it the files populate so now to find the error on the export

#Reload images in a transaction

I might be going off the wrong way but maybe the problem is the IP address in the path. In Revit the links are using the drive letter not the Ip address of the central file?

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

Thoughts

I would try debugging it this way:

Something is preventing all of the images from being appended to the reloadedFiles list, meaning that the test if imageName == fileName shown below is evaluating to False:

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

Output two separate lists, fileNames and imageNames and perform a set intersection to ensure that all items in imageNames are also present in fileNames. You can do something like this:

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

imageNames = []
for i in imgs:
    imageNames.append(i.ToDSType(True).Name)

OUT = fileNames, imageNames

If fileNames contains the following files:
[ABC.rvt, 1.jpg, 2.jpg, 3.jpg]

and imageNames contains the following files:
[3.jpg, 4.jpg, 5.jpg]

the only files which would be output in reloadedFiles would be this:
[4.jpg, 5.jpg]

1 Like

oh no I think i found the issue. is is when the image was re-pathed in revit it added the (2) to the end so image name does not = image path. is there an easy way to rename the image name to remove the (2) that is why only 1 repaths it doesn’t have the (2) on it

ugh

I just tried to rename the file, but it ended up just removing it from the Manage Images window.

image

I hard-coded a test like this:

TransactionManager.Instance.EnsureInTransaction(doc)

for fileName in fileNames:
	for i in imgs:
		ids = i.ToDSType(True)
		imageName = ids.Name
		if  imageName == 'Capture.png (2)':
			i.Name = 'Capture.png'

TransactionManager.Instance.TransactionTaskDone()

Not exactly sure how to do what you’re trying to achieve.

that sucks. I could manually delete the images and then reinsert them but this is going to happen all the time many of our projects have a (2) after the images.

Thinking about this again…what is the end goal? Are you trying to reload all of the images from their equivalents in a new directory? e.g. If you have these images:

C:\1.jpg
C:\2.jpg

and you want them to instead point to these images:

D:\1.jpg
D:\2.jpg

You would have to use the ReloadFrom method rather than just Reload. I’m still a bit confused by the script written in the other thread. Essentially, the logic reads like this:

If imageName (in Revit) matches the name of fileName (somewhere on a drive), then reload the image itself in Revit.

If your goal is to just reload all images in a file, you can take out the fileNames list altogether:

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

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

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

#Reload images in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for i in imgs:
	i.Reload()
TransactionManager.Instance.TransactionTaskDone()

Sorry to jump in but you do not need to do what you are doing on line 24/25 you can combine it as follows( eg add “[-1]” to the end of the split brackets).

1 Like

I tried your way a few times and keep getting errors. when I just replace

#Reload images in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for i in imgs:
	i.Reload()
TransactionManager.Instance.TransactionTaskDone()

I get

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 34, in
Exception: The associated image file of the ImageType doesn’t exist.

Line 34 is the i.reload()

If I just cut and paste your code word for word I get the same error for the same line.

Thanks again for everyone’s help this is giving me so much more dynamo experience.

oh and the end goal is just to reload all the image links in a file prior to printing CD’s (we have 30+ image links). The designers keep changing their material boards that we have linked in our drawings and don’t notify anyone of the change. so I wanted to have a quick reload all images button for the PM to use prior to printing a set.

(ultimately I would love to have a reload all images then print to pdf button lol)

@jarod.tulanowski it might be worth adding a checker that will grab the “Path” associated with the image, then using the “OS” Python module you can use the IsFile to check if the file still exists or can be accessed.

If they still exist then reload them, if not then report these out that the file cannot be accessed or does not exist.

This might help you narrow down if it is only one image file path that is causing the issue or if it is because one of your images was created within revit via rendering then save image as because this would not have a way to reload.

still confused. the image’s do exist it is just when you repath an image (with the same name) to a different directory it adds the (2) after it. I can manually reload each one without a problem I just can’t get dynamo to do all of them at once.

The reason we get the (2) is that we have placeholder images in our template. once we start a new project the designers place in their images with the same names in the new project directory. once I repath to the new directory I get the (2) because it is the same name as the original just with a new path (revit ugh issue lol)

I did unload an image and then reinsert it and the (2) disappeared but I would hate to do that for each project every time.

Like I said we have about 30+ images linked and manually clicking on each one before printing a final set is a P.I.T.A lol

Thanks for the help though (I just wish I was better at python than I am)

Just to clarify, you are using Reload From rather than Reload, right?

For simplicity, let’s just call your directories A and B. You have a template file with placeholder images all located in Directory A. The design team creates a new project using the template and copies all images into Directory B. However, all of the image references are still pointing to the original location (Directory A). You are then looking for a way to easily point all of the image references to Directory B rather than A where each of the images share the same file name (independent of how they appear in the Manage Images window which has (2) next to many of them).

Is that right?

Not exactly. yes and no. the design team uses the same name but with a different date. so we manually repath them with the new name once. (sometimes it adds the (2) and sometimes it doesnt) (I wish they kept them the same name but they dont). I can let all the teams that they cant have a image link with the (2) after it but would like to repath all the images despite the name

The problem falls after the pathing the designers keep updating the images over and over during the course of the project.

So the only thing I want to accomplish is a way to reload all images in a project without selecting any options. If the image is in the project (no matter what the name and path is) just reload it

P.S. I know the (2) only shows up about 5% of the time but want the reload to work even with it or without

image%20error%20reload

I think you should build in a temporary error checker to see if it is every imagetype or if it is specific one or type.

Something as follows:
image

Also if you have changed the location of the image then it should be a reloadfrom not a reload, therefore you need to put in a string file path.

1 Like

we only use jpg’s and 2 of the 30 load fine the other 28 have the (2) after them

to help you out with reload and reload from, here is a simple graph i did it with UI using datashape package. Do test it out and see if it works for your case


reload image.dyn (34.8 KB)