question

Rykou avatar image
0 Likes"
Rykou asked Rykou commented

Autobuild adjustable model by code

I'm trying to use flexscript auto-build a model, but I'm confused about whether building a system with parallel processors is feasible or not. I mean, set the quantity of processors from 1 to 2 with code and it can auto-build from a system with one processor(video1) to a system with parallel processors(video2)。

I had used flexscript to auto-build the model. But I don't know if it is possible to auto-build the model by setting the number of processors with code or not. Please refer to the attached file.


flexscript autobulid.fsm



FlexSim 23.1.2
flexscriptusing codeautobuild
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

Kavika F avatar image
1 Like"
Kavika F answered Rykou commented

Hey @Rykou, I expanded on the code you wrote. All you have to do is add a variable that stores the number of processors you want. In the model I made, I decided to hook that up to a Parameter Table, but a simple local variable with a number in the code would work too.

Some highlights of the code I added/changed:

int numProcessors = Model.parameters.NumProcessors;
// int numProcessors = 2; // This can be any number you want

Either of these ways will set the numProcessors variable.

Array processors = Array(numProcessors);
for (int i = 1; i <= numProcessors; i++) {
  processors[i] = Object.create("Processor");
}

This will create the number of processors you specified. Then you just have to modify your code to adjust the spacing and set the A-connections.

· 7
5 |100000

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

Rykou avatar image Rykou commented ·

Thanks for your reply, it is very helpful.

I have another question. How to destroy all the current objects when the stop time is reached? I have tried using loop in the model ,but it doesn't work.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Rykou commented ·
Table.query("DELETE FROM Objects() WHERE Object.up=model()")
2 Likes 2 ·
Rykou avatar image Rykou Jason Lightfoot ♦♦ commented ·

Hi @Jason Lightfoot , thanks for your reply. I'd tried code to destroy all the current objects when the stop time is reached. The error code is as follows.

if(current.time=stopTime)
{
   Table.query("DELETE FROM Objects() WHERE Object.up=model()");
}

I'd tried to change the condition of the if loop. But it didn't work.

flexscript autobulid.fsm(Software Version: FlexSim 23.1.2)

0 Likes 0 ·
Show more comments