question

Arun Kr avatar image
0 Likes"
Arun Kr asked Mischa Spelt answered

Exception Throwing After Creating Tracked Variables Using Code

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[k].name;

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

if(Name == SubnodeName)

{

treenode Subnode = TV.subnodes[k];

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

FlexSim 21.0.3
flexsim 21.0.3
swamisupport-tv.fsm (25.5 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

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered

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, ...);
5 |100000

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