question

Christopher S2 avatar image
3 Likes"
Christopher S2 asked Matthew Gillespie edited

How to pass the processor name to a getstream() command in a table cell

I have the following Global Table being used to provide cycle times for my processors.

The Row name is the name of the processor.

I pull the Cycle Time using the standard "Global Lookup Table" procedure:

Object current = ownerobject(c);
Object item = param(1);
/***popup:GlobalTableLookupNew*/
/***tag:Description*//**Using Global Lookup Table ( CycleTimes )*/
Variant tableID = /**\nTable: *//***tag:TableName*//**/"CycleTimes"/**/;


Table table;
switch (tableID.type) {
case VAR_TYPE_NODE: table = tableID; break;
case VAR_TYPE_STRING: table = Table(tableID.as(string)); break;
default:
table = reftable(tableID.as(int));
break;
}


Variant row = /**\nRow: *//***tag:row*//**/current.name/**/;
Variant col = /**\nColumn: *//***tag:col*//**/"CycleTime"/**/;


return table[row][col];

Is there a more efficient/elegant way to pass the processor name into the getstream() without hardcoding the processor name value? Thanks.

@Matthew Gillespie

FlexSim 18.2.2
global tablecommandsvariables
1.png (2.3 KiB)
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

·
Matthew Gillespie avatar image
2 Likes"
Matthew Gillespie answered Matthew Gillespie edited

The best way I can think of right now is to change the last line of code in the Global Table lookup code. Here are two options:

1) Pass the object into the table cell

If you change the last line to

return table.cell(row,col).evaluate(current);

You can change "getstream(current)" to "getstream(param(1))" so it looks like

beta(138.3, 200, 2, 10, getstream(param(1)))

2) Use a global variable

Or alternatively, add a treenode global variable (lets call it callingObj) and insert a line before the last

callingObj = current;
return table[row][col];

Then change "getstream(current)" to "getstream(callingObj)" so it looks like

beta(138.3, 200, 2, 10, getstream(callingObj))


Use a user command to avoid code duplication

In order to avoid having to change that line of code in every block of code, I would recommend adding a user command with the modified table look up code. Then you can copy the user command into the Process Time field of each processor. I've attached a sample model where I've done this.

passobjecttotable.fsm

gettablevalue uses the first method and is used by Processors 1 and 2

gettablevalue2 uses the second method and is used by Processors 10 and 11


· 4
5 |100000

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

Christopher S2 avatar image Christopher S2 commented ·

Thanks Matthew. I will try this and post back. I especially appreciate the user command idea.

0 Likes 0 ·
Christopher S2 avatar image Christopher S2 commented ·

Matthew,

I tried solution 1 and it worked great. I will keep solution 2 and the user command handy as I continue to develop this and other models.

Thanks,

Christopher

0 Likes 0 ·
Keith H3 avatar image Keith H3 commented ·

Hi @Matthew Gillespie, I have been using Option 1 for quite a while but since the release of 19.1.1 the exception: FlexScript exception: "Property "dataType" accessed on invalid node. at <no path>" appears in the System Console when clicking on the table cell containing the code. When called during the model run it works fine. Do you know what changed to cause this error message to appear?

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Keith H3 commented ·

This a bug. The table was updated to handle bundle tables with treenode pointers which introduced this error you're seeing. We'll get it taken care of. Thanks for pointing it out.

0 Likes 0 ·

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.