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

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

christopher_s2
Not applicable
68 Views
5 Replies
Message 1 of 6

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

christopher_s2
Not applicable

[ FlexSim 18.2.2 ]

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

14929-1.png

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

Accepted solutions (1)
69 Views
5 Replies
Replies (5)
Message 2 of 6

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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



Matthew Gillespie
FlexSim Software Developer

Message 3 of 6

christopher_s2
Not applicable

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

0 Likes
Message 4 of 6

christopher_s2
Not applicable

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
Message 5 of 6

keith_h3
Not applicable

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
Message 6 of 6

Matthew_Gillespie
Autodesk
Autodesk

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.



Matthew Gillespie
FlexSim Software Developer

0 Likes