Links to windows folders w/ numbers

Hello,

I’m very new to pyRevit and Python in general, so please excuse a silly question. I am making a very simple script that opens a windows explorer folder. From what I’m seeing, if there is a number in the folder structure, the script does not work. What am I doing wrong? Am I using the wrong command?

Works:
script.show_folder_in_explorer(“L:\Autodesk\Revit”)

Does not work:
script.show_folder_in_explorer(“L:\Autodesk\Revit\2022”)

The backslash character in python is a special character that can cause undesired things to happen if you don’t account for it. If you have a backslash in a string, you can either put an “r” before it, like this:

script.show_folder_in_explorer(r“L:\Autodesk\Revit\2022”)

or you can add an extra backslash behind each backslash, like this:

script.show_folder_in_explorer(“L:\\Autodesk\\Revit\\2022”)

Thanks! That was it.

If I may hijack my own thread, I’m thinking about taking this one step further and having it open a revit file. I can’t find documentation for opening files, is this possible?

I think you are looking for this:

https://apidocs.co/apps/revit/2022.1/5018fbdb-e7c3-6e32-7ca3-ee5c20dbc56f.htm

1 Like

Many Thanks! That is very helpful.

Perhaps I spoke to soon…I used the terminology for opening a Revit file, but recieved the following error:

AttributeError: ‘module’ object has no attribute ‘OpenAndActivateDocument’

I am loading these at the start of the script:

from pyrevit import revit, DB, UI
from pyrevit import forms
from pyrevit import script

If you post your code I can try to help see what went wrong, but here is a little test I did that worked for me.

You need to call the OpenAndActivateDocument method on your UIApplication. You can get that a number of ways. Here are a couple:

uiapp  = __revit__
#or
from pyrevit import HOST_APP
uiapp = HOST_APP.uiapp

Then you just call your method on that!

uiapp.OpenAndActivateDocument(r"YOUR DOCUMENT PATH")