How can we get the user files folder?
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
Best Answers
-
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
2 -
In case we do not have any analysis created you can get them using wbjn command:
userfilesdir = wbjn.ExecuteCommand(ExtAPI,"""returnValue(GetUserFilesDirectory())""")
4
Answers
-
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
0