NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert file globals with API

Hello,

how do I add new properties to file globals using API-calls. (VC++ and TS 3.5).
The following code snippet doesn't produce any errors but unfortunately doesn't
produce any file globals either.

seqfile = engine->NewSequenceFile();
propobj = seqfile->AsPropertyObject();

propobjTemp = engine->NewPropertyObject(TS:: PropValType_Boolean,VARIANT_FALSE,(_bstr_t)"",TS:: PropOption_SetOnlyIfDoesNotExist);
propobj->SetPropertyObject((_bstr_t)"FileGlobals.MyBoolean",TS:: PropOption_InsertIfMissing,propobjTemp);

propobjTemp = engine->NewPropertyObject(TS:: PropValType_Number,VARIANT_FALSE,(_bstr_t)"",TS:: PropOption_SetOnlyIfDoesNotExist);
propobj->SetPropertyObject((_bstr_t)"FileGlobals.MyString",TS:: PropOption_InsertIfMissing,propobjTemp);

propobjTemp = engine->NewPropertyObject(TS:: PropValType_NamedType,VARIANT_FALSE,(_bstr_t)"SomeContainer",0);
propobj->SetPropertyObject((_bstr_t)"FileGlobals.MyContainer",TS:: PropOption_InsertIfMissing,propobjTemp);

Thank you for your help.
Mike
0 Kudos
Message 1 of 6
(3,655 Views)

Hi,

You dont need to use the NewPropertyObject.

Just use the SetVal methods with the option set 1(PropOption_InsertIfMissing) eg SetValBoolean ()

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 2 of 6
(3,652 Views)
Thank you Ray for your answer.
That was my first approach to the matter, but unfortunately this
doesn't seem to work. No error but no new file global either. Is
there something I'm missing? See the following piece of code:

seqfileCase = engine->NewSequenceFile();
propobj = seqfileCase->AsPropertyObject();
propobj->SetValBoolean((_bstr_t)"FileGlobals.MyBoolean",TS::PropOption_InsertIfMissing,VARIANT_TRUE);


An additional question would be: If I want to add a container as
a new file global, how is that done? I can't use any of the SetVal
methods, can I?

Thanks.
Mike
0 Kudos
Message 3 of 6
(3,647 Views)

Hi,

A simple example for creating a container with sub properties.

This is not the only solution. You could use the InsertSubProperty but you would need to get a reference to a property object. which means either obtaining a reference from a type palette, or cloning a object.

Hope it helps.

Ray

Regards
Ray Farmer
0 Kudos
Message 4 of 6
(3,635 Views)
Your code is dynamically creating a new sub-property named FileGlobals that TestStand is not going to recognize as being "the" file globals.
 
"FileGlobals" is not a PropertyObject (ie. dynamic) sub-property of SequenceFile. The correct property path is "Data.FileGlobalDefaults". However, the "right" way to access the edit-time file globals is via the "static API" instead of using a lookup string: sequenceFile->FileGlobalsDefaultValues->SetValBoolean(...).
 
 
Also, don't forget to call the IncChangeCount method (on either the SequenceFile or PropertyObjectFile interface) whenever you modify a SequenceFile.
0 Kudos
Message 5 of 6
(3,628 Views)

Hi,

I have attached an example, which creates a new seqfile, inserts a FileGlobals (check out the lookup string - "Data.FileGlobalDefaults.MyBoolean"), increments the count and saves then releases the sequence file.

Its a bit crude. It will create the sequencefile "MySequenceFile.seq" in the same location where you open the main sequence file.

Hope it helps

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 6 of 6
(3,626 Views)