04-08-2015 03:23 AM
Dear NI community,
I create FileGlobals Variables as it is shown in the attachments. Variables are created, but at the same time, all existing if the file FileGlobals are deleted. Could anyone help, please, how can I insert variables, without affect on existing ones?
Thanks a lot in advance!
Solved! Go to Solution.
04-08-2015 03:35 AM
What is your lookup string ("String") for the variable?
Norbert
04-08-2015 03:37 AM
String - is name of my variable, which I want to create.
04-08-2015 03:44 AM
You did prepend the "FileGlobals." before the variable name itself, did you?
E.g. String = FileGlobals.MyGlobal
Norbert
04-08-2015 03:48 AM
Actually, I've tried it with FileGlobals at the beginning, and without.
In the first case, it puts created variables to container named "FileGlobals", and other FileGlobals vars are deleted.
In the second case, variables are created OK, but all others variables, existing ones, are deleted.
I have also concerns about usage of FileGlobalsDefaultValues reference - maybe, it causes problems? But I can not access FileGlobals reference from SequenceContext, while I'm not running sequence...
04-08-2015 04:03 AM - edited 04-08-2015 04:04 AM
Actually, my previous post is nonsense....
Using your approach within the sequence itself works for me to create the variable, but it doesn't show up in the execution itself (which is expected).
What i see from your code is that you didn't increment the change count of the file befor saving it.
I haven't checked without the sequence running, so here just a guess:
- Create a new variable
- Add this variable as InsertSubProperty to the FileGlobals
Norbert
PS: If my memory serves me correctly, this is something which is done in TS 2 class from NI as exercise.....
04-08-2015 04:40 AM
You are updating the sequence file programatically. If the sequence file is already opened in Sequence Editor, it needs to be refreshed. Hence, as Norbert specified, you need to use SequenceFile.IncChangeCount() before saving the sequence file. KB contains details about using IncChangeCount API.
If you are creating/modifying value of a FileGlobal variable of a sequence file in execution, you need to use Execution.GetFileGlobals() and modify the run time copy of the FileGlobals.
Note: Irrespective of using IncChangeCount() solves your issue or not, it is always good practice to use InChangeCount() when you are programatically modifying and saving the sequence file.
- Shashidhar
04-08-2015 06:02 AM
I was struggling with this issue all morning, and... I've realized, that this code doesn't delete variables from FileGlobals. Code for creation of sequences does it, which runs before this code... So, I've corrected that code - and it works now!
Thanks to everyone for help, I've found couple interesting things - I didn't know about this incrementation of file changes.