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?

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

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.

  1. int number = 11000;
  2. int numBays = 2;
  3. int numLevels = 5;
  4. double bayWidth = 48;
  5. double levelHeight = 6;
  6. treenode libraryRack = library().find("?Rack");
  7. Object firstRack = createinstance(libraryRack, model());
  8. function_s(libraryRack, "BasicRefreshTable", firstRack, numLevels, numBays, levelHeight, bayWidth);
  9. for(int i = 2; i <= number; i++) {
  10. Object obj = createcopy(firstRack, model(), 1, 0, 1, 0);
  11. obj.name = "Rack" + numtostring(i);
  12. obj.location.x = 0;
  13. obj.location.y = i;
  14. }
· 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.