question

Nana L avatar image
0 Likes"
Nana L asked Jordan Johnson commented

Create 100 proceesors with code

I need to create 100 "different" processors at the same time, how can I do this using the code?

Choose One
code
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

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Jordan Johnson commented

I suggest you try this in process flow, because you will probably set names and locations, too. You start with a scheduled source. Therein you assign a new label to the token to set the desired quantity. Then you insert a run sub process flow activity. The quantity of repeating comes from the previous set label. You assign to the children a label which contains the creationRank as value. This label can you use to set a number as a string in the name for the processor. The subflow starts with a start activity, then you put a create object activity, which creates the processor from the library in the model(). You assign the created object reference to a label at the token in the sub process. It is a child token. You need such a reference to set a name. Then you can insert a finish activity, because the processors have been created.

If you want to set names and locations, you inserts a source code activity for the naming and a change visual activity for the location in front of the finish activity

token.createdObjReference.name = “Processor”+string.fromNum(token.ID);// sets the name

ID is an example for a name, which contains the value from creationRank.

You should additionally append the reference of each created processor from the child token to the parent token, too. Later you are able to destroy the processors again with this data, otherwise each time you let run the model the same amount of processors are created additionally.

I hope, I was able to give you some hints. If you haven’t got any experiences with process flow, you should do some of the tutorials from the manual.

If you just want to duplicate a processor, you can copy your processor several times. There is also a tool named edit selected objects in view from main menu, which can duplicate all selected objects, change their names and copy parameters and function settings from an highlighted object to selected objects.

· 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.

Nana L avatar image Nana L commented ·

Hello, thanks for answering my question. I'm a rookie for FlexSim. I want to figure out that why I can't use this code to generate 100 processors at the same time without setting their location? Thanks!


for (int i = 1; i <= 100; i++) {

createinstance(node("/fixedresources/Processor", library()),model());

}

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Nana L commented ·

The code you wrote does create 100 processors, they just all have the same location:

0 Likes 0 ·
lotsofprocessors.gif (484.6 KiB)