question

Tom S4 avatar image
0 Likes"
Tom S4 asked Tom S4 commented

Bind NodeListArray from within SDT class

I can't figure out how to bind a NodeListArray for an SDT derivative.

For ODT, this is how I would do it for a list of SDTs:

class MyODTType: public ObjectDataType
{
   NodeListArray<MySDTType>::SdtSubNodeBindingType mylistofSDTs;
   
   void MyODTType::bindVariables() 
   {
      ObjectDataType::bindVariables();
      bindVariable(variable); // <---
   }
};

My SDTs also need to have a list of treenodes within them. Which bind macro do I use in this example?

class MySDTType: public SimpleDataType
{
   NodeListArray<treenode>::NodePtrType mylistofnodes;
   
   void MySDTType::bind() 
   { 
      SimpleDataType::bind();
      // What goes here? 
      // I have tried with no success:
      // bindNodeListArrayAsClass(treenode, mylistofnodes);
   }
};
FlexSim 23.0.1
module sdknodelistarraysdt
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

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Tom S4 commented

To bind a NodeListArray variable in a SimpleDataType, use bindSubNode:

bindSubNode(someNodeListArray, 0)

Basically, since the NodeListArray needs a parent node to place all its list elements under, it can be treated as a node in bindSubNode().

The bindClass() methods/macros deal with adding a new FlexScript API class, rather than binding member variables of a class. For more information, see:

https://docs.flexsim.com/en/23.0/Reference/DeveloperAdvancedUser/ModuleSDK/ExtendingFlexScript/ExtendingFlexScript.html#class

There is an example module file available on that page you might find helpful.

· 2
5 |100000

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

Tom S4 avatar image Tom S4 commented ·

Hi Jordan. This works for binding the NodeListArray, but when I try to add elements to it I am getting an exception.

NodeListArray<treenode>::NodePtrType mylistofnodes;
...
bindSubNode(mylistofnodes, 0);
...
mylistofnodes.add(mytreenode); // <--- here

Could be an issue happening elsewhere in my code, but I believe I have isolated it here. I'll investigate, but do you have any ideas on what could be causing this? There error I'm getting is just a generic exception in processeventinlist.

0 Likes 0 ·
Tom S4 avatar image Tom S4 Tom S4 commented ·
Nevermind, I figured it out. I was creating an instance of my SDT, then adding to its NodeListArray, then adding to the tree.

I fixed it by creating the instance, immediately adding it to the tree, and then manipulating the NodeListArray.

Thanks again for your help.

0 Likes 0 ·