I am now trying to write a Dynamo graph to repath broken PDF links when our main project folder gets renamed. I have succesfully figured it out for Revit and CAD links by reading the file path and changing the old folder name to the new name and repathing it using the Orchid node. However, I am unable to get any information on PDF links…
Hi
you can use the Revit API with this method
Example
import clr
import sys
import System
clr.AddReference("System.Numerics")
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
old_directory_path = IN[0]
new_directory_path = IN[1]
out = []
all_imagesType = FilteredElementCollector(doc).OfClass(DB.ImageType)
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for imgType in all_imagesType:
current_path = imgType.Path
print(current_path)
file_name = System.IO.Path.GetFileName(current_path)
if old_directory_path in current_path:
new_file_path = System.IO.Path.Join(new_directory_path, file_name)
if System.IO.File.Exists(new_file_path):
newImg_opt = ImageTypeOptions(new_file_path, False, ImageTypeSource.Link)
imgType.ReloadFrom(newImg_opt)
out.append(f"Success repath : {new_file_path}")
else:
out.append(f"Failed repath : {new_file_path}")
TransactionManager.Instance.TransactionTaskDone()
OUT = out