Autobuild adjustable model by code

Autobuild adjustable model by code

KANG
Not applicable
50 Views
8 Replies
Message 1 of 9

Autobuild adjustable model by code

KANG
Not applicable

[ FlexSim 23.1.2 ]

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



0 Likes
Accepted solutions (1)
51 Views
8 Replies
Replies (8)
Message 2 of 9

kavika_faleumu
Autodesk
Autodesk
Accepted solution

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

Message 3 of 9

KANG
Not applicable

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
Message 4 of 9

jason_lightfootVL7B4
Autodesk
Autodesk
Table.query("DELETE FROM Objects() WHERE Object.up=model()")
Message 5 of 9

KANG
Not applicable

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
Message 6 of 9

jason_lightfootVL7B4
Autodesk
Autodesk

I can't see where you've put that in the model but you're not testing if the times are equal - you need == to do that.

0 Likes
Message 7 of 9

KANG
Not applicable
I wrote it in Flexscript command console.(Line46~49)
0 Likes
Message 8 of 9

jason_lightfootVL7B4
Autodesk
Autodesk
It's commented out - so when did you expect to run it? What would trigger it? Again you're not testing equality - it needs '==' not '=' to do that.

Time is accessed through Model.time() or just time() not current.time - if that's what you're trying to do. Current is usual associated with the 'current' object on which code resides -since you haven't defined it within this script it is undefined and meaningless.

Message 9 of 9

KANG
Not applicable

I see, thank you for your reply with patient.

0 Likes