question

Frenk Gao avatar image
0 Likes"
Frenk Gao asked anthony.johnson answered

How to add bound members to a ObjectDataType sub-class manually?

I am trying to Implementing Module DLLs (SDK-Documentation-ModuleDevelopment).

I am trying to add a variable to the object.

But " Add FlexSim Variable" guide in Documentation is still use the "Adding FlexSim Object Variables Wizards" which has been removed. I must add bound members to a ObjectDataType sub-class manually.

So, these in the module sdk Documentation will not help:

  1. 1. Go back to Visual Studio. Right-click on
  2. the testmodule project in the Solution Explorer, and choose Add > New
  3. Item...
  4. 2. Choose "Add FlexSim Variable"
  5. and hit "Add"
  6. 3. For Class, enter
  7. "MyTaskExecuter". For Variable Name, enter "xonly". Check
  8. the box for "Number Data." Hit "Finish." Note - Sometimes
  9. this wizard can be finnicky and give you errors when you add variables. I think
  10. it may have to do with intelli-sense not being up-to-date, so sometimes if you
  11. just close and re-open, or just compile, it fixes itself.

Could you update the Documentation show me the C++ rockie how to add FlexSim Variable?

FlexSim 16.0.9
module sdk
5 |100000

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

anthony.johnson avatar image
0 Likes"
anthony.johnson answered

Sorry for the out-of-date Module SDK documentation. Mischa's answer still works, but in my own development I have dispensed with the "node_v_" usage that binds using bindobjectclassvariable() and instead use native types using bindVariable(). The class code that uses this would be something like the following:

  1. class MyTaskExecuter : public TaskExecuter
  2. {
  3. public:
  4. virtual void bindVariables(void);
  5. // ...
  6. double myDoubleVariable;
  7. NodeRef myNodeRef;
  8. treenode myVariableNode;
  9. ByteBlock myByteBlock;
  10. NodeListArray<OtherClassType>::StoredAttCouplingType objectList;
  11. };
Then the implementation of bindVariables() would be:
  1. #include "MyTaskExecuter.h"
  2. void MyTaskExecuter::bindVariables()
  3. {
  4. __super::bindVariables();
  5. bindVariable(myDoubleVariable);
  6. bindVariable(myNodeRef);
  7. bindVariable(myObjRef);
  8. bindVariable(myVariableNode);
  9. bindVariable(myByteBlock);
  10. bindVariable(objectList);
  11. }

The advantage of doing it this way is that the syntax is simpler to learn, and you can access values directly instead of using the older mechanism where you have to do a #define v_varName to get/set the value of a variable node. The bindVariable() macro can take what's demonstrated above, namely doubles, NodeRefs, treenodes (this binds the same as the old way, i.e. the class member points to a node in the object's variables tree), ByteBlocks (for string data), and NodeListArrays (those are bound the same as treenodes).

5 |100000

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

Mischa Spelt avatar image
3 Likes"
Mischa Spelt answered Mischa Spelt commented

Hi Frenk, here are the steps required to bind a variable in the class to a FlexSim variable:

1. In your class, create a variable and declare an override of the bindVariables function:

  1. class MyObject :
  2. public FlexSimObject /* or BasicFR, or ... */
  3. {
  4. public:
  5. virtual void bindVariables(void);
  6. // ...
  7. treenode node_v_myVariable;
  8. };

2. In the C++ file, call bindobjectclassvariable from the bindvariables function:

  1. void MyObject::bindVariables()
  2. {
  3. FlexSimObject::bindVariables(); // Call base class function
  4. bindobjectclassvariable( this->holder, &node_v_myVariable, "myvariableintree", "MyObject" );
  5. }

where

  • this->holder refers to the treenode associated to this object
  • node_v_myVariable refers to the class field (we use node_v_.. by convention for all such fields)
  • "myvariableintree" is the name of the node in the tree - node_v_myVariable will be associated to the treenode at MyObject>variables/myvariableintree, creating the node at this point if it does not exist
  • "MyObject" refers to the class by name as you have also spelled it in your createodtderivative.
· 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.