question

Ameen M Shabeer avatar image
0 Likes"
Ameen M Shabeer asked Phil BoBo edited

create On Draw Trigger in 1000+ NetworkNode using Script

Hi,

How can i create On Draw Trigger in 1000+ NetworkNode using Script window ?

i want to place following code in all the NetworkNodes !!

Object current = ownerobject(c);
treenode view = param(1);

if (PathVisibility == 1)
{
Object NN0 = current;
Object NN1 = current.outObjects[1];

double width = current.width;
drawtomodelscale(current);

double dx1 = NN1.location.x - NN0.location.x;
double dy1 = NN1.location.y - NN0.location.y;

double Angle1 = Math.degrees(Math.atan2(dy1 ,dx1));
double Distance1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);

fglRotate(Angle1, 0, 1, 0);
drawrectangle(0,width/2,0,Distance1,width,0,0,0, 255,255,0, 1, 0,0,0);
}

FlexSim 18.2.2
scriptusing codenetworknodecode windowobject treenode
5 |100000

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

Phil BoBo avatar image
4 Likes"
Phil BoBo answered Phil BoBo edited

You can use assertvariable() to assert the On Draw trigger on your object.

I would put that code in a user command and set the On Draw trigger of your network nodes to call the user command. That way, if you want to edit that code, you can edit it in one place without having to re-copy it to all of your nodes.

See the attached sample model. programmatically-set-ondrawtrigger.fsm

string drawCodeText = 
"/**Custom Code*/\n"+
"Object current = ownerobject(c);\n"+
"treenode view = param(1);\n"+
"return NetNode_OnDraw(current, view);";

treenode prevNN = 0;
for (int i = 1; i <= 5; i++) {
	Object NN = createinstance(library().find("?NetworkNode"), model());
	NN.width = 1;
	NN.location = Vec3(i * 5, 0, 0);
	treenode ondrawtrigger = assertvariable(NN, "ondrawtrigger", DATATYPE_STRING);
	ondrawtrigger.value = drawCodeText;
	switch_flexscript(ondrawtrigger, 1);
	buildnodeflexscript(ondrawtrigger);
	rebindobjectattributes(NN);
	if (prevNN) {
		contextdragconnection(prevNN, NN, "A");
	}
	prevNN = NN;
}

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

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

Also, here's a more robust version of your code that will work in all 3 dimensions and with any arbitrary number of network node output connections:

if (PathVisibility == 1)
{
  double width = current.width?;
  drawtomodelscale(current);
  
  for (int i = 1; i <= current.outObjects.length; i++) {
    Object otherNN = current.outObjects[i];
    
    double dx = otherNN.location.x - current.location.x;
    double dy = otherNN.location.y - current.location.y;
    double dz = otherNN.location.z - current.location.z;
    
    double Angle = Math.degrees(Math.atan2(dy,dx));
    double Distance = Math.sqrt(dx * dx + dy * dy);
    double Angle2 = Math.degrees(Math.atan2(dz,Distance));
    double Distance2 = Math.sqrt(dx * dx + dy * dy + dz * dz);
    
    fglRotate(Angle, 0, 1, 0);
    fglRotate(Angle2, 0, 0, 1);
    drawrectangle(0,width/2,-0.01,Distance2/2,width,0,0,0, 255,255,0, 1, 0,0,0);
    fglRotate(Angle2, 0, 0, -1);
    fglRotate(Angle, 0, -1, 0);
  }
}
2 Likes 2 ·
Roi Sánchez avatar image
0 Likes"
Roi Sánchez answered Ameen M Shabeer commented

Hi @Ameen MS,

After copying this code in the OnDraw trigger of one node, you can select all of the other nodes (in red), then click again in the one in which you pasted the code (highlighting it in yellow) and then go to View >> Edit Selected Objects and click in All Variables so as to paste all of the logic in the highlighted node to the others.

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

Ameen M Shabeer avatar image Ameen M Shabeer commented ·

Hi Roi Sánche

The NetworkNodes are dynamically created. So i am looking for a script to create triggers.

0 Likes 0 ·