From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Engine.SearchFiles

Solved!
Go to solution

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.

A.png

B.png

C.png

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?

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.
0 Kudos
Message 1 of 6
(1,571 Views)
Solution
Accepted by topic author bienieck

Hi bienieck

 

Does this help?

 

Engine Searcher.JPG

 

Regards

 

Steve

Message 2 of 6
(1,534 Views)

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?

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.
0 Kudos
Message 3 of 6
(1,518 Views)

@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.

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.
0 Kudos
Message 4 of 6
(1,507 Views)

Good stuff.  With a method with so many input options/variations there is always going to be a bit of a learning curve.

0 Kudos
Message 5 of 6
(1,487 Views)

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.

Message 6 of 6
(1,473 Views)