RevitLinkType.LoadFrom with modelpath

When I try to run loadfrom with modelpath but I keep getting an error asking for ExternalResourceReference. I’m creating the modelPath with the ModelPathUtils.ConvertUserVisiblePathToModelPath method. Is the issue here that it is actually creating a FilePath instead of a ModelPath? I thought that ModelPathUtils would have created a model path.

Here is my print statement with the error:

Temp-HVAC23.rvt needs reloading!

<Autodesk.Revit.DB.FilePath object at 0x0000000000004A63 [Autodesk.Revit.DB.FilePath]>

Autodesk.Revit.DB.FilePath

IronPython Traceback:
Traceback (most recent call last):
 File "L:\Revit\Development\PyRevit\DevTool\DevTool.extension\DevTools.tab\Development.Panel\StartReloadFrom.pushbutton\StartReloadFrom_script.py", line 149, in <module>
TypeError: expected ExternalResourceReference, got FilePath
for lT in linkTemp:
    for lTRF in linksToReloadFrom:
        if lT.name == lTRF:
            actualLinksReload.append(lT)
            print(lT.name + " needs reloading!")
            # print(lT.linkDicIndex)
            fileReloadName = file.replace(docNameDis, linkDic[lT.linkDicIndex][0])
            # print(fileReloadName)
            pathReloadString = folder + fileReloadName
            pathReload = ModelPathUtils.ConvertUserVisiblePathToModelPath(pathReloadString)
            print(pathReload)
            print(pathReload.GetType())

            linkType = doc.GetElement(lT.link.GetTypeId())
            # print(linkType)
            linkType.LoadFrom(pathReload, WorksetConfiguration)
1 Like

@Crapai

i can`t recreate your error… but i know it is sensitive topic to use the correct syntex like

# ❗ call path
path = @"C:\machine\tomp"

path = "C:\\machine\\tomp"

ModelPath class

1 Like

Sorry, I’m not sure what your trying to say here.

Am I misunderstanding the question? What does print(pathReloadString) return? Error indicates the wrong overload is being used because you didn’t provide a valid modelpath

This portion of the code covers the printout below.

            print(pathReloadString)
            pathReload = ModelPathUtils.ConvertUserVisiblePathToModelPath(pathReloadString)
            print(pathReload)
            print(pathReload.GetType())

\xxxx.local\XXXX\LIBRARY\Revit\Development\Issues\3 - Examples\2024-06-20 - Com - pyRevit Reload From\PA22024 - Central - M - R23.rvt
<Autodesk.Revit.DB.FilePath object at 0x000000000000080A [Autodesk.Revit.DB.FilePath]>
Autodesk.Revit.DB.FilePath

It is creating a file path, but the method is looking for a modelpath.

in the first two examples of the picture below you get both ways to get what you are trying to achieve

1 Like

So it looks like my actual issue was I wasn’t constructing the WorksetConfiguration correctly. I added the line with the wsconfig and it worked.

            wsconfig = WorksetConfiguration()

            linkType = doc.GetElement(lT.link.GetTypeId())
            # print(linkType)
            linkType.LoadFrom(pathReload, wsconfig)

How did you do that code search?

@Crapai

there are these 2 →

Cool,

Glad it helped.

This feature is something most people don’t know about, even though, I show it every time I got to speak in public.

if you go on this page, for example, you will find a small <> (Chevrons) sign at the top right of the page.
It uses the github API search feature to go through a defined list of website having Revit API related C# and python code:

1 Like

Another helpful resource for code examples HERE

1 Like

and its python counterpart https://python.hotexamples.com/
but be aware, in pyRevit, code is mostly iron python, mostly around the revit API, which is very niche.

1 Like