"pyrevit run" can't open model with non ASCII symbol in path

Hello,
I have a problem where when I try to open a model and run some scripts on it, everything works fine as long as the path to the model does not contain non ASCII character.

For example:
Following command work fine:
pyrevit run “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\OpenRevit.py” “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\1516_DSP_Kuchyne CP_detached.rvt” --revit=2024

But this command won’t open specified model:
pyrevit run “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\OpenRevit.py” “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\1516_DSP_Kuchyně CP_detached.rvt” --revit=2024

and will resolve in following error message:

==> Execution Environment
Execution Id: “ff733e90-0c87-4675-a29d-142398a25dda”
Product: 24.2.1 | Version: 24.2.10.64 | Build: 20240408_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024"
Clone: master | Deploy: “basepublic” | Branch: “master” | Version: “4.8.16.24121+2117” | Path: “C:\Program Files\pyRevit-Master”
Engine: DEFAULT | Kernel: IronPython | Version: 2711 | Runtime: True | Path: “C:\Program Files\pyRevit-Master\bin\engines\IPY2711PR\pyRevitLoader.dll” | Desc: “Custom pyRevit IronPython Engine”
Script: “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\OpenRevit.py”
Working Directory: “C:\Users\ruzicka\AppData\Local\Temp\ff733e90-0c87-4675-a29d-142398a25dda”
Journal File: “C:\Users\ruzicka\AppData\Local\Temp\ff733e90-0c87-4675-a29d-142398a25dda\PyRevitRunner_ff733e90-0c87-4675-a29d-142398a25dda.txt”
Manifest File: “C:\Users\ruzicka\AppData\Local\Temp\ff733e90-0c87-4675-a29d-142398a25dda\PyRevitRunner.addin”
Log File: “C:\Users\ruzicka\AppData\Local\Temp\ff733e90-0c87-4675-a29d-142398a25dda\PyRevitRunner_ff733e90-0c87-4675-a29d-142398a25dda.log”
==> Target Models
Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\1516_DSP_Kuchyně CP_detached.rvt
==> Execution Log
IronPython Traceback:
Traceback (most recent call last):
File “Q:\Jaroslav_Ruzicka\Kontrola_Modelu_Python\OpenRevit.py”, line 23, in
Exception: The document to be opened does not exist.

Script Executor Traceback:
Autodesk.Revit.Exceptions.FileNotFoundException: The document to be opened does not exist.
at Autodesk.Revit.UI.UIApplication.OpenAndActivateDocument(String fileName)
at Microsoft.Scripting.Interpreter.FuncCallInstruction3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at PyRevitLoader.ScriptExecutor.ExecuteScript(String sourcePath, IEnumerable1 sysPaths, String logFilePath, IDictionary2 variables)

Difference between those 2 commands is letter ě in revit file name. But the error pops out even when one of the files contains similar letters.

Is there a way around this?
It seems unfeesable to change the entire folder structure in our company to ASCII characters.

Thank you

Ahoj,
What is your code in OpenRevit.py? (at least up to line 23)

I have bunch of coments in the file above my code, but this is what executes:

from pyrevit import revit, DB, forms, HOST_APP
import RevitTests

uidoc = HOST_APP.uiapp.OpenAndActivateDocument(models[0])

doc = uidoc.Document

RevitTests.runTests(doc)


Line 23 is this:
uidoc = HOST_APP.uiapp.OpenAndActivateDocument(models[0])

The RevitTests.runTests(doc) runs several tests on the file like the one below, And when the path contains only ASCII arrors it does not produce any errors.:

def getRevitLinkCount(documentHandle):
collector = FilteredElementCollector(documentHandle)
linkedModels = collector.OfClass(RevitLinkType)

counter = linkedModels.GetElementCount()

return counter

Just an update. I did managed to fix the issue using a workaround.
I don’t think the problem was with the pyrevit itself but rather with the Revit API.

Pyrevit will launch Revit and it will launch the script on a selected model.
And then Revit API itself will throw this exception:
Autodesk.Revit.Exceptions.FileNotFoundException: The document to be opened does not exist.

Because it for some reason can’t work with path that has non ASCII character like “ě”.


The way I got around this is, I converted the path to a Revit model into 8.3 adress format using this function.

def get_short_path(long_path):
buffer_size = 512
buffer = ctypes.create_unicode_buffer(buffer_size)

if ctypes.windll.kernel32.GetShortPathNameW(long_path, buffer, buffer_size):
    return buffer.value
else:
    return None 

When launching my pyrevit script I convert all my file paths using the function above.

Then script launches normally, even if path to the file contains symbols like these: RBá+ěščéřížýáůú.rvt

1 Like

thanks for that!
Not everybody comes back and provide the feedback/answer