File Path Handling in Ansys Workbench

Ansys Workbench uses specific conventions for file or directory paths that are recorded to an Ansys Workbench journal, thus improving the portability of these paths between operating systems and user directories.

Handling Slashes as File Path Separators

Ansys Workbench uses the following conventions when a forward slash or a backslash is used as a path separator in a journal or script:

  • When a journal is written, all backslashes that occur in command arguments representing a path are converted to forward slashes.

  • When a command argument containing a path is read, all slashes are internally converted to the current platform-appropriate slash.

Handling of Absolute and Relative Paths

To ensure a robust recording and playback of scripts and journals, Ansys Workbench always records file and directory paths using a full (absolute) path. However, to facilitate portability of journals to different locations on a file system, a user path root is used to dynamically record and construct the absolute path.

The following conventions and capabilities are used with the user path root.

  • The default value of the user path root is taken from the Default Folder for Permanent Files preference. Changing this preference will take effect in your next session.

  • When a path is recorded to the journal and the start of the path matches the user path root, then the path is recorded using AbsUserPathName("RelativePathName"). This function constructs an absolute path based on the supplied relative path and the current user path root.

  • You can access or change the current value of the user path root within a script using the following commands:

    • pathRoot = GetUserPathRoot()

    • SetUserPathRoot(DirectoryPath="NewPathRoot")

    SetUserPathRoot does not change the Default Folder for Permanent Files preference but simply overrides the path root setting in the current session.

Example

Assume that the current value of the user path root is C:\Users\myUser\Projects. The command is:

Open(FilePath=r"C:\Users\myUser\Projects\proj1.wbpj") 

This would be journaled as:

Open(FilePath=AbsUserPathName("proj1.wbpj"))

You can override the current user path root to control the base location of files in your script:

SetUserPathRoot(DirectoryPath = "C:/Users/myUser1/Projects")
Open(FilePath=AbsUserPathName("proj1.wbpj")) # Read project from first location
SetUserPathRoot(DirectoryPath = "C:/Users/myUser2/Projects")
Open(FilePath=AbsUserPathName("proj1.wbpj")) # Read project from second location