Load families tool

Hi all, im new in the forum and new in pyRevit!
I made a script to load families in Revit. When the user click on the pushbutton, he is prompt to select family file. I use the “pick_file()” method. It’s work fine but i want to redirect the user on a specific folder but the “init_dir” argument doesn’t like work because the tool redirect in the last folder. PS: i use a variable for the “init_dir” because my families are stored on the cloud (ACC) and i use the desktop connector and need to have the currentUser name. It is possible to use a variable for the “init_dir” argument? Thanks in advance!
See my code:

# -*- coding: utf-8 -*-
import pyrevit
from pyrevit import revit, DB
import os
from pyrevit import script, forms

# get the current Revit document
doc = revit.doc

# specify the folder where the files are located
CurrentUser = os.path.expanduser('~')
FolderPath = os.path.join(CurrentUser + "/ACCDocs/Tetra Tech Inc/715-QIB - BIM_IT/Project Files/01_Familles/EL - Electricite/Alarme-Incendie (DAI)").replace("\\", "/")
CompleteFolderPath = FolderPath.replace("\\", "/")

# prompt the user to select the family file
family_path = forms.pick_file(file_ext='rfa', init_dir=str(CompleteFolderPath), restore_dir=False, multi_file=True, title='Selectionner la ou les familles à inserer')[0]
if not family_path:

# load the family into the project
trans = DB.Transaction(doc, 'Load Family')
except Exception as e:
import os
print (os.environ['USERPROFILE'])

@ginttaras Thanks for your reply! The print(os.environ[‘USERPROFILE’]) is a good alternative to get the current user. I got the same result of my variable in my code “CurrentUser”. I think i dont explain very well what is my issue. To get the current user isn’t a problem. I need to get the “FolderPath” and for that, i concatenate the “CurrentUser” + the other part of the specific path and it’s work fine. But when i put this variable “FolderPath” like an argument in the pick_file function, it doesn’t work.
The type of this argument need to be a string and thats why I add the prefix “str”. But it’s doesn’t work because when i run the script, im redirect to the last folder, not the folder I specify.
Any idea? Or do you know other method?

Hi @Dave_O
the issue is not there, it has to do with the use of backslash

proper syntax for folder path join should be:

user_folder = os.path.expanduser('~')
folder_path = os.path.join(user_folder + "\ACCDocs\\blah\\blah\\blah")

and use the folder_path in the pick_file method
no .replace needed

oh and better way to handle transactions IMHO

with DB.Transaction(doc, 'Load Family'):

no start, commit, …

Hi @Jean-Marc!
You right, the issue was related to the use of the backslash. At first i add the “.replace” because in the path some folder begin with a number and i have an other syntax error because a backslash follow by a number is like division (that’s what internet told me :)). Thanks a lot, i really appreciate! It’s work perfectly!

For your transaction trick, it doesn’t work, i saw that the family download (the desktop connector window) but this family isn’t in the project. With my line of code (start() and commit(), it’s work, the family appear in the Revit project browser.