question

Zach B3 avatar image
0 Likes"
Zach B3 asked Zach B3 commented

Set Fluid Mixer Recipe using CustomCode

I am able to write a line of code to Get the current value of one of the cells in the Recipe Table of a Fluid Mixer, but I am unable to Set a New value in one of the cells in the Recipe Table using a custom line of code based on table values. I have tried the following but it did not work:

var currentRecipeCell = getvarnode(Model.find("FluidMixer"), "recipetable").as(Table)[4][3];

var newValue = Table("myTable")[1][6];

currentRecipeCell = newValue;

Do you know why this code isn't setting the new recipe table values? I am getting the following error:

FlexScript exception: MODEL:/Tools/ProcessFlow/ProcessFlow/Custom Code>variables/codeNode

FlexSim 20.0.0
fluid mixerrecipe tablerecipe
· 1
5 |100000

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

Benjamin W2 avatar image Benjamin W2 commented ·

Hi @Zach B3,

Can you post your model? It will help us debug your specific code.

0 Likes 0 ·

1 Answer

Benjamin W2 avatar image
1 Like"
Benjamin W2 answered Zach B3 commented

Hi @Zach B3,

To edit the code node, you need to assign it directly. When you declare the var currentRecipeCell, it isn't reffering back to the original node in the recipetable. Instead, try the following:

int newValue = Table("myTable")[1][6];
getvarnode(Model.find("FluidMixer"),"recipetable").as(Table)[4][3] = newValue;

Please see the attached model and let me know if you have any questions.

dynamicloadrecipe.fsm


dynamicloadrecipe.fsm (913.4 KiB)
· 1
5 |100000

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

Zach B3 avatar image Zach B3 commented ·

thanks so much! it worked perfectly.

0 Likes 0 ·