How can we get the user files folder?

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

How can we get the user files folder of a project, from Mechanical?

Tagged:

Best Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    The following function can be used:

        import os
        def GetUserFileFolder(analysis):
            '''
                Return UserDir: path of the folder
            '''
            try:
                WorkDir = analysis.WorkingDir
                UserDir = os.path.dirname(WorkDir)
                for i in range(3):
                    UserDir = os.path.dirname(UserDir)
                UserDir = os.path.join(UserDir, 'user_files')
                if not os.path.exists(UserDir):
                    os.makedirs(UserDir)
                return UserDir
            except:
                ExtAPI.Log.WriteMessage("Error : Exception in GetUserFileFolder()")
                return None
    
  • Vishnu
    Vishnu Member, Employee Posts: 214
    Name Dropper First Anniversary Solution Developer Community of Practice Member First Comment
    Answer ✓
    Options

    In case we do not have any analysis created you can get them using wbjn command:

    userfilesdir = wbjn.ExecuteCommand(ExtAPI,"""returnValue(GetUserFilesDirectory())""")
    

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    This can also be used:

    def user_files_directory():
        user_files = ''
     
        if ExtAPI.Context == 'Project':
            user_files = GetUserFilesDirectory()
        elif ExtAPI.Context == 'Mechanical':
            import wbjn
            user_files = wbjn.ExecuteCommand(ExtAPI, "returnValue(GetUserFilesDirectory())")
        return user_files