network nodes connection by using global table

network nodes connection by using global table

jyothi_n
Not applicable
376 Views
2 Replies
Message 1 of 3

network nodes connection by using global table

jyothi_n
Not applicable

[ FlexSim 18.2.3 ]

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.

0 Likes
Accepted solutions (1)
377 Views
2 Replies
Replies (2)
Message 2 of 3

joshua_s
Not applicable
Accepted solution

Here's your code that will work now

int numRows = Table("GlobalTable1").numRows;
int x_Col = 2;
int y_Col = 3;
int z_Col = 4;
int Name_COL = 1;
treenode prevnode = NULL;
for (int i=1; i<=Table("GlobalTable1").numRows; i++) 
{
	
	int xLoc=Table("GlobalTable1").cell(i,x_Col).value;
	int yLoc=Table("GlobalTable1").cell(i,y_Col).value;
	int zLoc=Table("GlobalTable1").cell(i,z_Col).value;
	string newName = Table("GlobalTable1").cell(i,Name_COL).value;
	treenode nnode = createinstance(library.find("?NetworkNode"),model());
	 nnode.as(Object).location.x=xLoc;
     nnode.as(Object).location.y=yLoc;
     nnode.as(Object).location.z=zLoc;
    nnode.name=newName;
	if (objectexists(prevnode))
		contextdragconnection(prevnode, nnode, "A");
	prevnode = nnode;
}

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.

Message 3 of 3

jyothi_n
Not applicable

Thank you

0 Likes