Inherits SimpleDataType

The ObjectDataType class is the class that represents object data on a node. All nodes in the tree that have object data will have an associated instance of ObjectDataType. This is the parent class of FlexsimObject, from which all library objects inherit.

Objects of this class have the ability to use the pre-defined attribute nodes recognized by the engine, including some of the event handler attributes. They can also define the variables that the "variables" sub-node will contain. This class is generally used to create a very basic object.

Direct Child Classes

FlexsimObjectThe parent class of all libary objects


Virtual Methods

void bindVariables(void) Binds nodes in the variables attribute tree of the object for direct access

Attribute Binding

Attribute nodes are nodes that the engine will use if they are present. Attributes deal with things like view parameters (such as alignbottommargin and beveltype), events (such as OnClick and OnListen), and many other options. A complete list of attributes can be found in in FlexSim under Help > Attribute Hints. The engine will recognize and use attributes contained within any node of ObjectDataType.

Nodes that are used as attributes by the engine are displayed with blue names, as shown in the figure below. The "spatialx" attribute contains the x location of an object.

The ObjectDataType class provides member pointers to all attributes. Some pointers to lesser-used attributes are only allocated as needed to help save memory, but they will be automatically provided if necessary. A simplified representation of the ObjectDataType class is shown below:

The "node_b_" prefix signifies first that's it's a reference to a tree node, and second, the "b" means it is part of the "base" class, i.e. the ObjectDataType class. When an object of this type is created in the tree, all its attributes are bound. This means that for each attribute shown in the tree, a member pointer exists that points directly to the node in the tree. This allows the engine to access attribute nodes without searching through the tree every time. This kind of member pointer is often called a "fast pointer."

For example, let's start with a blank node. As soon as you add object data to that node, an instance of ObjectDataType is created in the engine, and the node in the tree points to that instance. Now, if we add the node "spatialx" to the object in the tree and then rebind its object attributes, the engine assigns the matching member pointer to the address of the "spatialx" node. The "spatialx" node points to its own data of 5.00.

The logic that searches attributes and assigns pointers is provided in the ObjectDataType class.


The bindVariables() method binds to custom class members that you add to the class. If you want to add members to the class that will be saved with the model, you need to bind them as variables in bindVariables(). Corresponding variable nodes will be stored in the object's variables tree.

Bind FunctionData TypeExample
bindVariable(double& varName)doublebindVariable(length) - binds a double length as a variable of the class.
bindVariable(treenode& varName)treenodebindVariable(myVarNode) - binds myVarNode as a quick access node in the object's variables tree. Note that the NodeListArray class has a treenode& casting operator, which means you can use this method to bind NodeListArrays as well.
bindVariable(NodeRef& varName)NodeRefbindVariable(myNodeRef) - binds a variable that has coupling pointer data and can point to some other node in the mode.
bindVariable(ObjRef& varName)ObjRefbindVariable(myObjRef) - binds myObjRef as a variable with couplint point data that points to an object.
bindVariable(ByteBlock& varName)ByteBlockbindVariable(myStr) - binds a variable with string (ByteBlock) data.

Event Handling

The way that the engine notifies objects of certain events firing is by executing the code contained in attribute nodes on an object. For example, if you want to fire some code when the user clicks on an object in the ortho view, then in the object's (or the object's class') attributes tree you add a text attribute with the name OnClick, toggle it as Flexscript/C++/DLL, then write code on that node's text. When the user clicks the object, the engine checks if that object has an OnClick attribute, and if it does, it executes that node.

This basic logical sequence extends to all object events, such as OnReset, OnReceive, OnSend, OnTimerEvent, OnDraw, etc.

In order to execute a member function on an event, you must:

  1. Create the event node in the tree.
  2. Toggle that node as C++.
  3. Insert code like: o(MyObjectType, c).myFunction([param1, param2...]);
  4. The o() macro retrieves a reference to the object of type MyObjectType from the node c, and calls myFunction()on that instance.
  5. Compile the project.

This directs the engine to execute the member function associated with the node.