question

lariwalker avatar image
0 Likes"
lariwalker asked lariwalker commented

How do I add code-generated control points to code-generated AGV paths?

Hi,

I'm using code to draw a grid of AGV paths, with control points at each intersection. The problem is when I add a control point in position, it doesn't "snap" onto the path as expected.


/**Custom Code*/

Model.find("AGVNetwork").subnodes.clear();

int length = 5;
int width = 5;
List CPoints = List("ControlPoints");






//vertical lines

for (int i = 0; i <= width; i++){
treenode path = createinstance(node("/AGV/StraightPath",library()),model());
setloc(path,i*725.2+362.6,362.6,0);
setrot(path, 0,0,90);
setsize(path, 725.2*length,1,1);
getvarnode(path, "isTwoWay").value = 1;
function_s(path, "finalizeSpatialChanges");

}

//horizontal lines

for (int i = 0; i <= length; i++){
treenode path = createinstance(node("/AGV/StraightPath",library()),model());
setloc(path,362.6,i*725.2+362.6,0);
setsize(path, 725.2*width,1,1);
getvarnode(path, "isTwoWay").value = 1;
function_s(path, "finalizeSpatialChanges");
}

for (int i = 0; i <= length; i++){
for (int j = 0; j <= length; j++){
treenode controlpoint = createinstance(node("AGV/ControlPoint", library()), model());
setloc(controlpoint,i*725.2+362.6,j*725.2+362.6,0);
CPoints.push(controlpoint.value);
}
}


Also, I'd like to write a code to delete all control points at the start. How could I write some code that finds all "controlpoint" objects and deletes them?

Thanks!

FlexSim 22.2.3
agvcodecontrol points
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

Patrick Zweekhorst avatar image
0 Likes"
Patrick Zweekhorst answered lariwalker commented

Hi @LariWalker ,

You could use some code that looks like the code below:

Array cps = [];
forobjecttreeunder( model() )
{
    if( isclasstype( a, "AGV::ControlPoint" ) )
    {
        cps.push( a );
    }
}


for( int i = 1; i <= cps.length; i++ )
{
    Object cp = cps[ i ];
    cp.destroy();
}

Hope this helps you further

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

lariwalker avatar image lariwalker commented ·
Thanks! That works perfectly.


Do you have any idea of how to get my generated control points to "snap" onto the paths I create?

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ lariwalker commented ·
Use setProperty - see my examples.
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

Don't use finalizespatial changed - instead, cast the paths and control points as objects and use <object>.setProperty(<propertyname>,<value>);

Paths eg.:

    path.setProperty("StartLocation",start);
    path.setProperty("EndLocation",start+xunit*gridSizeX);
    path.setProperty("IsTwoWay",1);

Control Point:

        controlpoint.setProperty("Location", Vec3(xlocs[i],ylocs[j],0));
0 Likes 0 ·
lariwalker avatar image lariwalker Jason Lightfoot ♦♦ commented ·
That did it. Thanks so much
0 Likes 0 ·