question

Judith S avatar image
0 Likes"
Judith S asked Matt Long commented

Meaning of the programming

Could somebody explain me what de programming in Custom Code means?

Software Version 17.0.2

- -----
custom code
· 1
5 |100000

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

Matt Long avatar image Matt Long commented ·

This code would be better written as:

offsetsx(token.Item).value = 1;
offsetx(token.Item).value = 0;
1 Like 1 ·
Ben Wilson avatar image
2 Likes"
Ben Wilson answered

Hi @Judith S,

setnodenum(token.Item.find(">spatial/offsetsx"), 1);

Let's break apart what is going on. First of all, the setnodenum() function uses the following syntax to set a value to a treenode:

setnodenum(treenode thenode, num value)

So the 2nd parameter in the top code is easy: 1. We are setting the value of some treenode to 1.

And which treenode are we going to set a new value on? For the code you're asking about, the treenode is defined using the following:

token.Item.find(">spatial/offsetsx)

Several things are happening here:

  1. token is a reference to some token moving through your Process Flow.
  2. From token you are using dot-syntax to access the Item that has been associated with the token.
  3. From Item, you are calling that Object's find() method, which will traverse into its tree data to search for a node at the given data tree path.
  4. The path looks like this: >spatial/offsetsx. You can kind of relate this path to a path on your hard drive, like C:\Program Files\FlexSim. FlexSim is a folder under Program Files. The \ character has a meaning. So do other characters, like the :. Let's look at FlexSim's path syntax for this code:
    1. > - dive into the Item object's tree data
    2. spatial - find the node named spatial
    3. / -the forward slash indicates to look at the previous node's child nodes
    4. offsetsx - this is the name of the child node of spatial that we are looking for
    5. This image shows an example of how this path would work:

So in the end, the meaning of those two lines of code is this:

  1. Set the Item's offsetsx attribute (which helps define its size in the x-dimension) to 1.
  2. Set the Item's offsetx attribute (which helps define the Item's position along the x-dimension) to 0.

The whole concept of offsets vs spatials is a good topic for a brand new question. If you need to explore that topic, go ahead and ask a new question. Or comment below with any follow-up questions regarding reading the code examples above.


5 |100000

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

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Joerg Vogel edited

The code is a combination with and without dot-syntax. The command setnodenum(obj node, num value) sets the value at the node. In your example the node is the spatial attribute in the object that belongs to the label Item of the token. "offsetsx" is the attribute of the size of the shape in x direction. "offsetx" is the location of the shape in x direction. You can edit those values, if you press the "Edit" button next to "Shape Factors" on the General Tab in the area "Appearance". It is the top most area on the left side.

That was the short description:

"token" the typical green chip in ProcessFlow

"Item" a label at the token, typically it contains a reference to an item in the 3D-Model

"find( )" a method a node or object by name or path string: here a path string ">spatial/offsetsx"

">" entering the objects attributes

"spatial" subnode of the features of the visual look: Object location, rotation, size of the yellow and red frame and the location, rotation and size of the shape of an object. Object is in this case an item, too.

"offsetsx" offset is the part of the node name to identify the shapes attributes. "..s.." identifies the size. "..x" identifies the direction.

If there isn't a character between offset and the coordinate direction then the attribute describes the location. The last chracter you can find is "r". It is the character for a rotation "offsetry".

Previous to these two code lines you find the header. The header contains the references of the activity which are passed into this function as parameters in short "param(..)". The value in the function is the number of the parameter. The parameters are casted into different variables of the classes: Object, treenode, Token and put into variables with the names: current, activity, token and processFlow.

The function ownerobject( ) returns a reference of the object which executes the current source code of the activity. It is the ProcessFlow where you find the activity in.

5 |100000

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