question

jyothi N avatar image
0 Likes"
jyothi N asked jyothi N commented

network nodes connection by using global table

network-nodes.fsm

in my model i want to create network nodes by using coordinates and name taken from the global table and they have to be connected by using A type .i added some script in that model and i was unable to execute it.

FlexSim 18.2.3
network nodestravel networksa connection
network-nodes.fsm (22.9 KiB)
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

Joshua S avatar image
1 Like"
Joshua S answered jyothi N commented

Here's your code that will work now

  1. int numRows = Table("GlobalTable1").numRows;
  2. int x_Col = 2;
  3. int y_Col = 3;
  4. int z_Col = 4;
  5. int Name_COL = 1;
  6. treenode prevnode = NULL;
  7. for (int i=1; i<=Table("GlobalTable1").numRows; i++)
  8. {
  9. int xLoc=Table("GlobalTable1").cell(i,x_Col).value;
  10. int yLoc=Table("GlobalTable1").cell(i,y_Col).value;
  11. int zLoc=Table("GlobalTable1").cell(i,z_Col).value;
  12. string newName = Table("GlobalTable1").cell(i,Name_COL).value;
  13. treenode nnode = createinstance(library.find("?NetworkNode"),model());
  14. nnode.as(Object).location.x=xLoc;
  15. nnode.as(Object).location.y=yLoc;
  16. nnode.as(Object).location.z=zLoc;
  17. nnode.name=newName;
  18. if (objectexists(prevnode))
  19. contextdragconnection(prevnode, nnode, "A");
  20. prevnode = nnode;
  21. }

If you want to access functions or variable inherent to a specific class, you should use .as(Class), rather then put the class in front unless you are defining a new object. The code above also limits the iterations to the length of your rows in the global table now.

· 1
5 |100000

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