Exception Throwing After Creating Tracked Variables Using Code

Exception Throwing After Creating Tracked Variables Using Code

arunTTT2P
Explorer Explorer
13 Views
1 Reply
Message 1 of 2

Exception Throwing After Creating Tracked Variables Using Code

arunTTT2P
Explorer
Explorer

[ FlexSim 21.0.3 ]

Hi,

I was trying to create some tracked variables using code before the run start of the simulation model, after deleting the existing tracked variables other than TimeInSystem and WorkInProgress. Some exceptions are thrown after pressing the reset button and couldn't understand the reason What could be the reason?

Also attaching the model.

exception: Exception caught in TreeNode::callMemberFunction() c++/dll execution. Throwing... MAIN:/project/exec/globals/nodefunctions/resettrackedvariable c: MAIN:/project/exec/globals/nodefunctions/resettrackedvariable thisClass: MAIN:/project/exec/globals/nodefunctions/resettrackedvariable

exception: FlexScript exception: MAIN:/project/events/OnResetModel/reset tracked variables

exception: Exception Caught in ObjectFunction28__project_exec_globals_nodefunctions_resettrackedvariable object: MAIN:/project/exec/globals/nodefunctions/resettrackedvariable class: MAIN:/project/exec/globals/nodefunctions/resettrackedvariable

treenode TV = Model.find("Tools/TrackedVariables");

for(int k=TV.subnodes.length;k>=3;k--) // Removes existing tracked variables

{

string SubnodeName = TV.subnodes.name;

string Name = "Bay" + string.fromNum(k-2);

if(Name == SubnodeName)

{

treenode Subnode = TV.subnodes;

Subnode.destroy();

}

}

int NumOfBays = 7;

for(int k=9;k<=9 + NumOfBays;k++) // Adds new variables

{

TrackedVariable newTV = TrackedVariable.init(TV, STAT_TYPE_TIME_SERIES, 0.0, STAT_USE_HISTORY | STAT_IGNORE_WARMUP);

TV.last.name = "Bay" + string.fromNum(k-8);


}

Regards,SwamiSupport_TV.fsm

Arun KR

0 Likes
Accepted solutions (1)
14 Views
1 Reply
Reply (1)
Message 2 of 2

mischa_spelt
Advisor
Advisor
Accepted solution

You are calling TrackedVariable.init on TV = Model.find("Tools/TrackedVariables"), but that function initializes a tracked variable on the specified node, not a new subnode. So you'll probably get an error because TV.last does not exist.

Try first creating an empty subnode, and then initializing a TV on that:

treenode newTvNode = TV.subnodes.add();
newTvNode.name = "Bay " + string.fromNum(k - 8);
TrackedVariable newTv = TrackedVariable.init(newTvNode, ...);