question

Sunada C avatar image
0 Likes"
Sunada C asked Matthew Gillespie edited

Rack 3D creation flexscript

I am trying to create racks using code and the model is hanging repeatedly while doing it. The hardware is not an issue as I have a pretty loaded computer. Please see the code below. The length of the Global Table is 11000 rows. So essentially I am trying to create 11000 rack objects. How do I go about doing this?

int number = 11000;//gettablerows("GlobalTable1"); int numBays = 2; int numLevels = 5; double bayWidth =48; double levelHeight = 6; for(int i = 1; i <= number; i++) { Object obj = createinstance(library().find("?Rack"), model()); function_s(node("/?Rack", library()), "BasicRefreshTable", obj,numLevels,numBays, levelHeight,bayWidth); obj.name = "Rack" + numtostring(i); obj.location.x = gettablenum("GlobalTable1",i,2)-bayWidth; obj.location.y = gettablenum("GlobalTable1",i,3); } Object source = createinstance(library().find("?Source"),model()); source.name = "Source_1"; source.location.x = -10; source.location.y = -10; //contextdragconnection(node("MODEL:/Source_1"),model().find(gettablestr("GlobalTable1",1,1)),"A"); //contextdragconnection(node("MODEL:/Source_1"),model().find(gettablestr("GlobalTable1",2,1)),"A");
FlexSim 18.2.2
rackcodeautobuildobject creation
· 3
5 |100000

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

Joshua S avatar image Joshua S commented ·

your code would be easier to go through if you posted it with better formatting like below

for (int i=0;i<10;i++)
{
	print(i);
}

0 Likes 0 ·
Sunada C avatar image Sunada C Joshua S commented ·

@Joshua S : I would also like to automatically rotate them in the RZ axis by -90 degrees. I am trying to do that using the view table and selecting the group and rotate but it keeps hanging.

0 Likes 0 ·
Sunada C avatar image Sunada C commented ·
int number = gettablerows("GlobalTable1");
int numBays = 2;
int numLevels = 5;
double bayWidth =48;
double levelHeight = 6;
for(int i = 1; i <= number; i++) {
 Object obj = createinstance(library().find("?Rack"), model());
 function_s(node("/?Rack", library()), "BasicRefreshTable", obj,numLevels,numBays, levelHeight,bayWidth);
 obj.name = "Rack" + numtostring(i);
 obj.location.x = gettablenum("GlobalTable1",i,2)-bayWidth;
 obj.location.y = gettablenum("GlobalTable1",i,3);
}
Object source = createinstance(library().find("?Source"),model());
source.name = "Source_1";
source.location.x = -10;
source.location.y = -10;
//contextdragconnection(node("MODEL:/Source_1"),model().find(gettablestr("GlobalTable1",1,1)),"A");
//contextdragconnection(node("MODEL:/Source_1"),model().find(gettablestr("GlobalTable1",2,1)),"A");
0 Likes 0 ·

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo commented

The main issue is that createinstance() gives the object a unique name. As the size of the model increases, the code to verify that the name is unique takes longer and longer.

You can get around this issue by just creating the first object with createinstance() and then using createcopy() to create the other ones.

Also, the "?" syntax in a node path causes a recursive string search. You are doing this 22000 times when you only need to do it once if you save the pointer to that object as a local variable.

You also don't need to adjust the size of each rack if you change the first one before making copies.

int number = 11000;
int numBays = 2;
int numLevels = 5;
double bayWidth = 48;
double levelHeight = 6;
treenode libraryRack = library().find("?Rack");
Object firstRack = createinstance(libraryRack, model());
function_s(libraryRack, "BasicRefreshTable", firstRack, numLevels, numBays, levelHeight, bayWidth);
for(int i = 2; i <= number; i++) {
	Object obj = createcopy(firstRack, model(), 1, 0, 1, 0);
	obj.name = "Rack" + numtostring(i);
	obj.location.x = 0;
	obj.location.y = i;
}
· 4
5 |100000

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

Sunada C avatar image Sunada C commented ·

@phil.bobo : Thank you. Additionally, I am trying to rotate all of these racks by 90 degrees along Z axis. How do I do that. I tried creating groups and then rotating it but it hangs up again

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Sunada C commented ·

I don't understand the complication. Use the following code to change the rotation the same way you changed the location:

obj.rotation.z = 90;
1 Like 1 ·
Sunada C avatar image Sunada C Phil BoBo ♦♦ commented ·

@phil.bobo

I set-up a source and a queue in the 3-D model and then I use the script to set the connection between the Queue and the Rack. In the source I am using a schedule source and in the queue I am doing send to port (By global table lookup). For some reason when I run the simulation it just deletes the rack in the 3D model and the flow items do not move from the queue to the rack. Please see the model attached below. Your input would be helpful.

rack-storage-doubt.fsm

0 Likes 0 ·
Show more comments