question

Hitesha N2 avatar image
0 Likes"
Hitesha N2 asked Phil BoBo commented

How to autobuild conveyor's as per layout with auto-connection between them?

FlexSim 18.2.2
autobuildconveyor moduleautoconnect
· 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.

Joerg Vogel avatar image Joerg Vogel commented ·

@Hitesha N2, can you be a bit more precise why you need it, and can you tell us what your knowledge level is? Many Thanks!

0 Likes 0 ·
Hitesha N2 avatar image Hitesha N2 Joerg Vogel commented ·

@Jörg Vogel Attaching an example model.

Zip folder has AutoCAD layout and FlexSim model in which layout is imported.

In AutoCAD layout, white color lines/curves indicate conveyor, cyan color circle indicate station and red color line indicate conveyor stops. After importing layout into FlexSim, i will drag and drop conveyor, station and photo eye to match with white lines, cyan color circle and red color line respectively.

However, I want my FlexSim model to have conveyor, station and photo-eyes at their respective places automatically and in connected state, after I import AutoCAD layout into FlexSim.

Please suggest.

0 Likes 0 ·

1 Answer

Phil BoBo avatar image
3 Likes"
Phil BoBo answered Phil BoBo commented

Use createinstance() to create the conveyor. See: Create a straight conveyor in code?

Use function_s(conveyor,"finalizeSpatialChanges") to update the automatic connections to nearby conveyors. See: Create conveyor system in code

Check the Load Snap Points box in the Background Drawing Wizard to load the AutoCAD data into the tree in a format that you can read with code. See How are snap points used?

Access that data using the Table FlexScript API. For example:

Object dwg = Model.find("FlexsimModelBackground");
Table vertexLocations = getvarnode(dwg, "snapPoints").subnodes["Vertex Locations"];
Table lines = getvarnode(dwg, "snapPoints").subnodes["Lines"];
Table arcs = getvarnode(dwg, "snapPoints").subnodes["Arcs"];
Table circles = getvarnode(dwg, "snapPoints").subnodes["Circles"];


treenode LibraryStraightConveyor = node("?StraightConveyor", library());
for (int i = 1; i <= lines.numRows; i++) {
	int index1 = lines[i][1] + 1;
	double x1 = vertexLocations[index1][1];
	double y1 = vertexLocations[index1][2];
	double z1 = vertexLocations[index1][3];
	int index2 = lines[i][2] + 1;
	double x2 = vertexLocations[index2][1];
	double y2 = vertexLocations[index2][2];
	double z2 = vertexLocations[index2][3];
	
	Conveyor conveyor = createinstance(LibraryStraightConveyor, model());
	conveyor.setLocation(x1, y1, z1);
	
	double dx = x2 - x1;
	double dy = y2 - y1;
	double dz = z2 - z1;
	double length = sqrt(dx*dx + dy*dy);
	conveyor.size.x = length;
	conveyor.rotation.z = Math.degrees(Math.atan2(dy, dx));
	setvarnum(conveyor, "rise", dz);

	function_s(conveyor, "finalizeSpatialChanges");
}
· 7
5 |100000

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

Hitesha N2 avatar image Hitesha N2 commented ·

@phil.bobo

Thank you for answer.

Using above code, i am able to create conveyor with auto connections. There are some other lines in layout, which are not conveyor but are created as conveyor in FlexSim. To solve this, I will insert a layout which only has conveyor lines.

Now, in my layout, i will have conveyor, station and photo-eye locations. I would like to create stations and photo-eyes at locations per AutoCAD layout, automatically. Also these stations and photo-eyes need to be placed on conveyor(created prior) with an automatic connection. How this can be done?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Hitesha N2 commented ·

You can create decision points, stations, and photoeyes in the same way you create conveyors: with the createinstance() command. You can automatically connect them in the same way as conveyors: with the function_s(obj, "finalizeSpatialChanges") command.

treenode LibraryDecisionPoint = node("?DecisionPoint", library());
for (int i = 1; i <= circles.numRows; i++) {
	int index = circles[i][1] + 1;
	double radius = circles[i][2];
	double x = vertexLocations[index][1];
	double y = vertexLocations[index][2];
	double z = vertexLocations[index][3];
	Object decisionPoint = createinstance(LibraryDecisionPoint, model());
	decisionPoint.setLocation(x, y, z);
	function_s(decisionPoint, "finalizeSpatialChanges");
}
treenode LibraryStation = node("?Station", library());
for (int i = 1; i <= circles.numRows; i++) {
	int index = circles[i][1] + 1;
	double radius = circles[i][2];
	double x = vertexLocations[index][1];
	double y = vertexLocations[index][2];
	double z = vertexLocations[index][3];
	Object station = createinstance(LibraryStation, model());
	station.setLocation(x, y, z);
	function_s(station, "finalizeSpatialChanges");
}
treenode LibraryPhotoEye = node("?PhotoEye", library());
for (int i = 1; i <= circles.numRows; i++) {
	int index = circles[i][1] + 1;
	double radius = circles[i][2];
	double x = vertexLocations[index][1];
	double y = vertexLocations[index][2];
	double z = vertexLocations[index][3];
	Object photoEye = createinstance(LibraryPhotoEye, model());
	photoEye.setLocation(x, y, z);
	function_s(photoEye, "finalizeSpatialChanges");
}
0 Likes 0 ·
Hitesha N2 avatar image Hitesha N2 Phil BoBo ♦♦ commented ·

Station, Photo-Eye are getting inserted but not getting connected to the conveyor.

There is no event function "finalizeSpatialChanges" under Station and Photo-Eye in library.pe-station-eventfunctions.png

0 Likes 0 ·
Show more comments