10-07-2021 10:14 AM
I'm trying to automate Find (CTRL+SHIFT+F) in TestStand. It seems to me that I can do it with the Engine.SearchFiles
method. However, I can't force it to do what I want. Does anyone know how to use it?
In my example, you can see how I configure Find and what I have in the Results window.
When I try to use the following expression I'm getting an empty SearchResult object.
Locals.SearchResult = RunState.Engine.SearchFiles(
@"B\Tes", 'searchString - Pass the string or regular expression for which to search. To use regular expressions, you must specify SearchOptions_RegExpr for the searchOptions parameter.
SearchOptions_IncludeSubsequenceFiles, 'searchOptions - Pass one or more SearchOptions constants. Use the bitwise-OR operator to specify multiple search options.
SearchFilterOptions_Steps OR SearchFilterOptions_ModuleStepProps, 'filterOptions - Pass one or more SearchFilterOptions constants. Use the bitwise-OR operator to specify multiple search filter options.
SearchElement_StringValue, 'elementsToSearch - Pass one or more SearchElements constants. Use the bitwise-OR operator to specify multiple elements to search.
{}, 'limitToAdapters - Pass an array of AdapterKeyNames constants to indicate the steps of which adapters to search. Pass an empty array or NULL to search steps that use any adapter.
{}, 'limitToNamedProps - Pass an array of property names under which to limit the search. Pass an empty array or NULL to search all properties. If you specify names of properties to which to limit the search, TestStand searches only those properties with the names you specify and all their subproperties.
{}, 'limitToPropsOfNamedTypes - Pass an array of type names to which to limit the search. Pass an empty array or NULL to search instances of all types. Use this parameter to limit the search instances of all types. Use this parameter to limit the search to instances of the types you specify.
{}, 'openFilesToSearch - Pass an array of PropertyObjectFile references to specify already open files in which to search. You can pass an empty array or NULL for this parameter.
{@"C:\TEST"} 'directoriesAndFilePaths - Pass an array of directories and/or file paths to indicate which files to load and search. All paths must be absolute paths. If you specify a directory, TestStand searches all sequence files under the directory and any of the subdirectories. You can pass an empty array or NULL for this parameter.
)
I don't know if I can set NoOption in searchOptions
for example by specifying 0, so I used SearchOptions_IncludeSubsequenceFiles
even that it is not exactly what I have in my Find window.
TestStand Help mentions that I can use NULL
for some of the parameters. What does it mean? Nothing
? IND
? NAN
? 0
? The only thing that worked was {}
. What does NULL
mean in TestStand Help?
How to use Engine.SearchFiles
method to recreate what I have in the Find window?
Solved! Go to Solution.
10-08-2021 08:14 AM
10-09-2021 02:46 PM
Yes, it helped. Thanks.
It seems that the problem I had was related to the strange behavior of this method. I think it uses SearchOptions_WholeWordOnly
even if it is not specified. I mean, even if I do not set this option this method will match "Test" but not "Tes".
Another thing, there are two interesting methods for SearchMatch
object: UpdateForReplace
and UpdateForReplaceValue
. Both have the following remark:
This method does not perform the actual replace operation. Use PropertyObject
objects to edit the file or property before calling this method.
So, how exactly the "search and replace" workflow should look like?
10-10-2021 05:15 AM
@bienieck wrote:
I think it uses
SearchOptions_WholeWordOnly
even if it is not specified. I mean, even if I do not set this option this method will match "Test" but not "Tes".
I was wrong. If I use wire 0 instead of any option it works as it should.
10-11-2021 02:51 AM
Good stuff. With a method with so many input options/variations there is always going to be a bit of a learning curve.
10-11-2021 03:23 PM
re: "This method does not perform the actual replace operation. Use PropertyObject
objects to edit the file or property before calling this method."
I read this as the SearchMatch.Update... methods only update the set of search matches to be consistent with the state of things after you perform a replace... in case you are using the search match objects to implement something like the sequence editor Find Results tab.
Looks like you still have to program the replace operation....or at least SearchMatch isn't going to do the actual replacement for you. I presume that would start with calling SearchMatch members to get the location of the replacement and then calling the PropertyObject members that are appropriate to perform the replacement at the specified location.