Hello,
how can i copy a "Tag" array into a "C#" array?
I tried so:
LocalFormArray = Globals.Tags.TagArray.Value;
LocalFormArray = Globals.Tags.TagArray[].Value;
LocalFormArray = Globals.Tags.TagArray.Values;
LocalFormArray = Globals.Tags.TagArray[].Values;
but none of these worked.
Thanks!
copy a "Tag" array into a "C#" array
Re: copy a "Tag" array into a "C#" array
Can you clarify exactly what you are trying to achieve and what type of array you are declaring in C#?
This will work but not sure if it's what you're looking for:
VariantValue[] cArray = new VariantValue[Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
cArray[index++] = gdi.Value;
}
This will work but not sure if it's what you're looking for:
VariantValue[] cArray = new VariantValue[Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
cArray[index++] = gdi.Value;
}
Re: copy a "Tag" array into a "C#" array
What I try to do, if possible, is to copy all the values contained in a Tag array
in a C# array, so declared:
float[] LocalFormArray = new float[8];
in just one code line.
For the moment I do so:
for (int i = 0; i < 8; i++)
{
LocalFormArray = Globals.Tags.TagArray .Value;
}
in a C# array, so declared:
float[] LocalFormArray = new float[8];
in just one code line.
For the moment I do so:
for (int i = 0; i < 8; i++)
{
LocalFormArray = Globals.Tags.TagArray .Value;
}
Re: copy a "Tag" array into a "C#" array
If you're only doing it once, I can't see a better way to do it. If you are doing it multiple times you could create a function:
private float[] getArray(GlobalDataItem tag)
{
float[] resultArray;
try
{
resultArray = new float[tag.ArraySize];
for (int i = 0; i < tag.ArraySize; i++)
{
resultArray = tag.Value;
}
}
catch
{
resultArray = null;
}
return resultArray;
}
and call it like so:
float[] myArray = getArray(Globals.Tags.TagArray);
I think this should work.
private float[] getArray(GlobalDataItem tag)
{
float[] resultArray;
try
{
resultArray = new float[tag.ArraySize];
for (int i = 0; i < tag.ArraySize; i++)
{
resultArray = tag.Value;
}
}
catch
{
resultArray = null;
}
return resultArray;
}
and call it like so:
float[] myArray = getArray(Globals.Tags.TagArray);
I think this should work.
Re: copy a "Tag" array into a "C#" array
Thanks a lot, that was the solution I was looking for.
About your previous post:
VariantValue [] = new CArray VariantValue [Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
CArray [index ++] = gdi.Value;
}
can you do the same but only for GlobalDataItems which belong to a recipe?
Thanks!!
About your previous post:
VariantValue [] = new CArray VariantValue [Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
CArray [index ++] = gdi.Value;
}
can you do the same but only for GlobalDataItems which belong to a recipe?
Thanks!!
Re: copy a "Tag" array into a "C#" array
This seems to work:
Tools.Recipe.RecipeItems ris = Globals.Recipe1.RecipeItems;
VariantValue[] cArray = new VariantValue[ris.Count];
int index = 0;
foreach (Tools.Recipe.RecipeItem ri in ris)
{
CArray[index++] = ((GlobalDataItem)ri.DataItem).Value;
}
Tools.Recipe.RecipeItems ris = Globals.Recipe1.RecipeItems;
VariantValue[] cArray = new VariantValue[ris.Count];
int index = 0;
foreach (Tools.Recipe.RecipeItem ri in ris)
{
CArray[index++] = ((GlobalDataItem)ri.DataItem).Value;
}
Re: copy a "Tag" array into a "C#" array
Thanks for your help Greg, it works great!
I ask one more thing, if I can,
how can I create an event that will fire whenever a GlobalDataItam changes of value?
Thanks a lot in advance!
I ask one more thing, if I can,
how can I create an event that will fire whenever a GlobalDataItam changes of value?
Thanks a lot in advance!