Multiple paths in XS_MACRO_DIRECTORY
Environment
Not environment-specific
Question:
Multiple paths in XS_MACRO_DIRECTORY caused some macros to fail. How can I fix this?
Answer:
Some macros check for existence of additional files required to run properly; for example, executables or pictures. If XS_MACRO_DIRECTORY contains multiple paths, those macros need to be modified to search for files in those paths where the files are located. The XS_MACRO_DIRECTORY can be used to specify to paths, global and a local, for recorded macro files. Since Tekla Structures version 21.1 the old macro list dialog isn’t used, and instead macros are listed in the Components & applications catalog instead
As an example, the following is defined:
set XS_MACRO_DIRECTORY=%XSDATADIR%environments\common\macros;%XSDATADIR%environments\uk\user-macros
The following command in a macro would fail:
if (System.IO.File.Exists(@System.Environment.GetEnvironmentVariable("XS_MACRO_DIRECTORY") + @“\executable_name.exe”)))
{
…
}
else
{
// File not found.
}
Because “%XSDATADIR%environments\common\macros;%XSDATADIR%environments\uk\user-macros\executable_name.exe” is not a valid file path.
The solution is to split the paths and check for the existence of the executable file in those paths; so, the above command would have to be changed to the following.
string TempMacroDirectory = System.Environment.GetEnvironmentVariable("XS_MACRO_DIRECTORY");
bool FileFound = false;
string CheckPath = "";
string ValidPath = "";
char[] Delim = { ';' };
string[] MacroDirectory = TempMacroDirectory.Split(Delim, System.StringSplitOptions.RemoveEmptyEntries);
foreach (string CheckDir in MacroDirectory)
{
if (CheckDir.Length > 0)
{
CheckPath = Path.GetDirectoryName(CheckDir + "\\");
if (CheckPath.Length > 0)
{
if (File.Exists(CheckPath + "\\executable_name.exe"))
{
ValidPath = CheckPath + "\\executable_name.exe";
FileFound = true;
break;
}
}
}
}
if (FileFound)
{
// “ValidPath” contains the file name with complete path, use it to run the executable.
}
else
{
// File not found.
}
Multiple paths in XS_MACRO_DIRECTORY caused some macros to fail. How can I fix this?
Answer:
Some macros check for existence of additional files required to run properly; for example, executables or pictures. If XS_MACRO_DIRECTORY contains multiple paths, those macros need to be modified to search for files in those paths where the files are located. The XS_MACRO_DIRECTORY can be used to specify to paths, global and a local, for recorded macro files. Since Tekla Structures version 21.1 the old macro list dialog isn’t used, and instead macros are listed in the Components & applications catalog instead
As an example, the following is defined:
set XS_MACRO_DIRECTORY=%XSDATADIR%environments\common\macros;%XSDATADIR%environments\uk\user-macros
The following command in a macro would fail:
if (System.IO.File.Exists(@System.Environment.GetEnvironmentVariable("XS_MACRO_DIRECTORY") + @“\executable_name.exe”)))
{
…
}
else
{
// File not found.
}
Because “%XSDATADIR%environments\common\macros;%XSDATADIR%environments\uk\user-macros\executable_name.exe” is not a valid file path.
The solution is to split the paths and check for the existence of the executable file in those paths; so, the above command would have to be changed to the following.
string TempMacroDirectory = System.Environment.GetEnvironmentVariable("XS_MACRO_DIRECTORY");
bool FileFound = false;
string CheckPath = "";
string ValidPath = "";
char[] Delim = { ';' };
string[] MacroDirectory = TempMacroDirectory.Split(Delim, System.StringSplitOptions.RemoveEmptyEntries);
foreach (string CheckDir in MacroDirectory)
{
if (CheckDir.Length > 0)
{
CheckPath = Path.GetDirectoryName(CheckDir + "\\");
if (CheckPath.Length > 0)
{
if (File.Exists(CheckPath + "\\executable_name.exe"))
{
ValidPath = CheckPath + "\\executable_name.exe";
FileFound = true;
break;
}
}
}
}
if (FileFound)
{
// “ValidPath” contains the file name with complete path, use it to run the executable.
}
else
{
// File not found.
}