question

Patrick Cloutier avatar image
0 Likes"
Patrick Cloutier asked Patrick Cloutier commented

Generate AGV paths from coordinates in an imported Excel file

I'd like to generate AGV paths from coordinates in an imported Excel file.

Are there commands to create paths from code for example: createpath(x1,y1,z1,x2,y2,z2,a,b,c)?

I can't find such a command.

Thanks,

FlexSim 18.1.0
path
· 2
5 |100000

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

Emily Hardy avatar image Emily Hardy ♦ commented ·

@Patrick Cloutier, did either of these solutions work for you?

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier Emily Hardy ♦ commented ·

This was a question from a potential client who wants to buy Flexsim. I only needed to know if it can be done. Since I was pretty confident that one of these methods will work I told him YES.

But I didn't try these. Yet.

So I don't know which answer to accept.

0 Likes 0 ·
Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo edited

You can create AGV paths the same way you create other objects: using createinstance(). See: How to create and join AVG paths in flexscript

For example, the following code creates a straight path and a curved path:

treenode path1 = createinstance(node("/AGV/StraightPath",library()),model());
setsize(path1,3,1,1);
setloc(path1,1,0,0);
function_s(path1, "finalizeSpatialChanges");

treenode path2 = createinstance(node("/AGV/CurvedPath",library()),model());
setloc(path2,4,1,0);
setvarnum(path2, "radius", 1);
setvarnum(path2, "startAngle", -90);
setvarnum(path2, "sweepAngle", 90);
function_s(path2, "finalizeSpatialChanges");


create-paths.png (3.4 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.

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

There are no commands to do it. The view does it through edit modes. You could try to replicate the edit modes, but I couldn't get it to work. Here is some code for a user command that might be able to get you started, but that I can't get to work correctly for the curved parts:

/**Custom Code*/
Vec3 point1 = Vec3(param(1), param(2), param(3));
Vec3 point2 = Vec3(param(4), param(5), param(6));
int isCurved = param(7);
int xFirst = isCurved && param(7) == 1;
treenode view = param(8);

treenode agvNetwork = node("/AGVNetwork", model());
treenode container = agvNetwork;
if (!objectexists(container))
	container = model();

string className = isCurved ? "AGV::CurvedPath" : "AGV::StraightPath";
int appendNr = 1;
string name = "Path";
while (objectexists(node(concat(name, numtostring(appendNr, 0, 0)), agvNetwork)))
	appendNr++;
	
treenode theClass = findmatchintree(library(), getname(first(classes(a))) == className);
if (!objectexists(theClass))
	return 0;
		
treenode path = setname(createinstance(theClass, container), concat(name, numtostring(appendNr, 0, 0)));
set(spatialsx(path), 0);
setcenter(path, point1.x, point1.y, point1.z + 0.5 * zsize(path));

setselectedobject(view, path);
if (xFirst) {
	function_s(path, "dragEnd", point2.x, point1.y, point1.z, view);
} else {
	function_s(path, "dragEnd", point1.x, point2.y, point1.z, view);
}
function_s(path, "dragEnd", point2.x, point2.y, point2.z, view);
function_s(path, "finalizeSpatialChanges", view);

And here's an example using that code:

treenode view = node("VIEW:/active/MainPanel/BackPanel/SplitterXPane/SplitterYPane/TabPane/TabControl/Perspective>viewwindowtype/Perspective/1/../../..");
createAGVPath(0, 0, 0, 5, 0, 0, 0, view);
createAGVPath(5, 0, 0, 6, 1, 0, 2, view);
createAGVPath(6, 1, 0, 6, 2, 0, 0, view);
createAGVPath(6, 2, 0, 5, 3, 0, 1, view); // This curve doesn't work right

Note that it requires the active view. Also note that I can't guarantee that this approach will really work long term, because it isn't designed for people to do this outside the drag-drop interface. But good luck!

5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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