question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Phil BoBo converted comment to answer

How can you check if a table is in bundle mode within code?

Hi,

I have a function that reads a text file into a global table and sometimes I want the table to be in bundle mode and sometimes not. If in bundle mode, I cannot write to the row headers so I would need to know if the table is in bundle mode.

How can I check if a table is in bundle mode, i.e, "Use bundle" is checked, within the code? I cannot seem to find a node that is one or zero depending on if the table is in bundle mode. The only difference is that the data node is different in the tree.

The code below checks for the subnodes of the table data node. Bundles have zero child nodes for the data node. But is this reliable? Can there be a table in not bundle mode with zero rows or is there always at least one subnode to the data node for a normal, i.e. not bundle table?

//reference table
Table table = Table("Table");

//check if table has bundle mode set
return table.as(treenode).subnodes.length;

Kind regards,

Axel

Choose One
custom codebundle
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Arun Kr avatar image
5 Likes"
Arun Kr answered

Hi Axel Kohonen,

Checking the data type of the data node is a better approach than checking the content.

When you reach for the node, using a sampler. We can only create a reference using the Table() method. And accessing the datatype of a table object is not possible using dot method. So you can downcast the table reference to a treenode and access the datatype. It will look like this.

treenode DataNode = Table("GlobalTable1").as(treenode);
if(DataNode .dataType == DATATYPE_BUNDLE)//Checking the datatype of the data node
{	
	print("Table bundle enabled");
}
else
{
	print("Table bundle not enabled");
}


To answer the second question. Yes a table reference can exist with zero rows. For instance, if you want to clear the global table on reset and populate the global table with new information during the simulation run. You need to have a table with zero rows

Regards,

Arun KR

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.