NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Search Class : UpdateForReplace

Hi,

I'm using TS 3.1f1.
I need to find and replace a word in a Sequence File, using the TestStand API.

I use the Search method (which returns a SearchResults object), and then I can get each SearchMatch object.
So I can find all occurrences of the word in the sequence file.
But the UpdateForReplace method doesn't seem to work... I have no error but nothing is replaced.
I think I'm doing something wrong but I don't know what.

Could you please explain me how to replace the string ?

Bruno
0 Kudos
Message 1 of 11
(5,525 Views)

Hi Bruno,

I haven't used this before but I think the sequence of events should be

1. Get a PropertyObject reference to the item you wish to search.

2. With the PropertyObject reference use PropertyObject.Search method to return a SearchResult object.

3. Using the SearchResult object you can determine the Number of Matches and when the Search is complete
   (SearchResult.IsComplete and SearchResultNumMatches)

4. Use the return SearchResult object to get the search matches with SearchResult.GetMatch which returns a SearchMatch object.

5. Using this SearchMatch object you should be able to use the UpdateForReplace method.

Unfortunately, I am unable to my example working, I cannot find any matches so my UpdateForReplace errors. As soon as I get it working, (if it does work) I'll post an example.

Regards

Ray Farmer

 

 

 

Regards
Ray Farmer
0 Kudos
Message 2 of 11
(5,505 Views)
Hi Bruno,
 
I have an example for you.
 
In my example, I am limiting my search on the Locals in the MainSequence. I have a piece of text in Locals.Text. I also have a local called Locals.cow.
The search text is in the FileGlobals which is equal to "cow" and the replacement text is in the Locals and is equal to "Dog". As you can probably gather I am changing very occurrance of "cow" with "Dog". Hence the reason for putting the search variable any else but the Locals as this would have been changed as will.
 
What I have found out is the UpdateForReplace method doesn't actual replace the actual property, you have to use the PropertyObject methods to do this.
[
from the Help:

This method does not perform the actual replace operation itself. Use PropertyObject to edit the file or property before calling this method.

]

You will notice that my Local.cow doesn't actually get changed, I think I should be handling this differently.

Also you will note that I am only changing the runtime values. If you what to change the actual sequence file, you will have to change the static value or work from the PropertyObjectFile.

Hope this helps.

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 3 of 11
(5,491 Views)
Hi Ray,

Your example helps me to understand how to use the 'UpdateForReplace' function.
I can now replace all string values.

But I need to replace all occurrences of a string in a sequence file.
By example, the string could be a part of a step name.

How can I know if I should change the property value or the property name ?
Your sequence doesn't replace the 'Locals.cow' variable. And I don't know how to do that.
What is the result of the 'UpdateForReplace' function in that case ? And how to use the result ?


I think your example corresponds to the "Replace value" button in SeqEdit.
And I want to do something like the "Replace found text"
button in SeqEdit.

Need your help.
Regards.
Bruno
0 Kudos
Message 4 of 11
(5,483 Views)
Hi Bruno,
 
I think you have to check the type by using the 'SearchMatch.PropertyValueType' or maybe 'SearchMatch.TypeCategoryOfMatch' and base your actions on the results of these checks.
 
Yeah, my example doesn't change the text of the property Locals.cow. I will look at this later today.
 
Regards
Ray Farmer
 
 
Regards
Ray Farmer
0 Kudos
Message 5 of 11
(5,483 Views)
Hi Bruno,

Ray is correct. Use TypeCategoryOfMatch to determine whether the match was in a Type or not. Since you probably don't want to edit types this way, you probably will only want to do the edit if this property returns TypeCategory_None. If it does, you can then use the PropertyValueType to determine if the match was in the value, name, or comment. Then you can use the GetPropertyPath method to get the lookupstring to use with the PropertyObject API to change the property in the file.

Hope this helps,
Doug
0 Kudos
Message 6 of 11
(5,465 Views)
One more thing I forgot to mention. In order for all replaces to succeed you will need to update the match records by calling UpdateForReplace after you make each edit, otherwise the lookupstrings you get from GetPropertyPath for later matches will not reflect the previous edits and therefore might be incorrect. UpdateForReplace updates the lookupstrings, matched text, and match locations in matches that are effected by an edit.

Doug
0 Kudos
Message 7 of 11
(5,462 Views)
Hi Doug,

Thanks for your reply but I'm still very confused :

I'm using the 'Search' method of the sequence file Property Object.

And from the help for TypeCategoryOfMatch I read :
"This property always returns TypeCategory_None when you create the search using PropertyObject.Search. The value is only valid when you create the search with Engine.SearchFiles."

I have checked this. I always get zero (=TypeCategory_None).

You say that I can use the PropertyValueType to determine if the match was in the value, name, or comment.
But the PropertyValueType returns the type of the property (corresponding to the PropertyPath returned by the SearchMatch object).

So if 'Locals.MyVar' is a variable of type Number, PropertyValueType returns PropValType_Number
.

And if 'Locals.MyVar2' is a string variable, PropertyValueType returns PropValType_String.
How can you determine if you should change the value, name, or comment in this case ?

It does'nt seem to me as easy as you say.
Have you got an exemple that you can send to me ?

Bruno


0 Kudos
Message 8 of 11
(5,441 Views)
You are correct about the type category of match, if you aren't doing SearchFiles you don't need to worry about that. And also about propertyvaluetypes, I confused that with Match Element. Sorry about that. What you need is the match element. You can get it by calling GetLocation on the match object. That will also give you the location of the matched string within the whole string.

Hope this helps. Sorry for the confusion.
-Doug
0 Kudos
Message 9 of 11
(5,435 Views)

Bruno,

I have modified my example so that it modifies the Property Name by checking the value of the MatchElement returned back from the GetLocation.

If its equal to 1 then I deal with the Name of the Property

if it equal to 4 then I deal with the value of the Property. In this case I still only deal with a String value. Therefore you would have to do further checks to find out what the Type is.

(the next thing to deal with is handling the SequenceFile)

Hope this helps

Regards

Ray Farmer

Regards
Ray Farmer
Message 10 of 11
(5,424 Views)