File path to a file

Hi all!
I think my issue is quit for dummies’’ so sorry in advance##
i have a cod that part of his operation is to load a title block to the revit file.
the same with a shared parameter txt file’ that loads the sp to the project file.
so far so good now, both files located in a kind of helpers modules, located inside the pyrevit extensions,
i call this files using the path of my machine as -

ttblock_file = r"C:\Users\Dotan\Desktop\MyExtension\ListGen_master.lib\revit\ListGen_TitleBlock.rfa"

now, how can i set this path’s so that they will fit in my client’s machine ?
try’s with os module and got lost…
I’m adding my code
help will be highly appreciated

> ttblock_file = r"C:\Users\Dotan\Desktop\MyExtension\ListGen_master.lib\revit\ListGen_TitleBlock.rfa"

def LoadTTblockIfMissing(titleBlcName, wasRun = False):

    TBCollector = FilteredElementCollector(doc).OfClass(FamilySymbol) 


    TBElementList = TBCollector.ToElements() #list of elements


    #get defult title block

    for tb in TBElementList:

        tbName = [tb.FamilyName for tb in TBElementList] #list of elements names

        if titleBlcName not in tbName:

            transaction = Transaction(doc, "load family")


            ttbfile = doc.LoadFamily(ttblock_file)


            wasRun == True


            wasRun = 'File Exsist'


    return wasRun   

#=========== STARTS CODE ================================

# Exmple ======================================================

stb = LoadTTblockIfMissing('ListGen_TitleBlock', wasRun = False)


    # open up the sp file from disc at given path - must have in order to open in revit

    path = r"C:\Users\Dotan\Desktop\MyExtension\ListGen_master.lib\proced\ListGen_SharedParameter.txt"

    fileExist = System.IO.File.Exists(path)

    openRead = System.IO.File.OpenRead(path)


    df = DefinitionFile

    def df(application, fileName):

        application.SharedParametersFilename = fileName

        return application.OpenSharedParameterFile()


    spf = df(app, path) 


    exp = sp.IsSharedParamExist(spf)


    indxList = exp[0]

    spParamList = exp[1]


    # in case of runing the code again with difrent category

    indx =  [idx for idx, value in enumerate(exp[1])]

    splist = exp[1]


    asp = sp.AddSharedParamToProject(indx, splist)




Sounds like you need to use user’s environmental variables. For example below is a path to a CSV file called “Space Names.csv” on any users desktop

import os 

filepath = os.path.join(os.environ["USERPROFILE"],"Desktop", "Space Names.csv")

Search working with environment variables in python for more examples…


Also you can do it this way:

from os.path import expanduser
homepath = expanduser("~")
filepath = homepath + "\\Desktop\\ListGen_TitleBlock.rfa"

or like this:

import os
homepath = os.getenv('HOME')
filepath = homepath + "\\Desktop\\ListGen_TitleBlock.rfa"