@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!
@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.
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"); }
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?
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"); }
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
8 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved