Alyson P avatar image
Alyson P asked Alyson P commented

Is it possible to add a point in map through FlexScript?

Hello, guys.

I need to add several points to a map and do it manually would take a long time. Is it possible to create some points through FlexScript, set their coordinates and add them to the map? I also need to make connections among these created points through FlexScript and further I will try to read an Excel sheet with the city names and their geographical coordinates in order to add all cities "automatically".

Thanks for your attention.

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

Phil BoBo avatar image
Phil BoBo answered Alyson P commented

Below is a script that programmatically creates various GIS objects and sets their properties.

// Create a map object if one does not exist
Object map = model().find("UtahMap");
if (!map) {
    map = createinstance(library().find("/GIS/Map"), model()); = "UtahMap";
    map.setSize(30, 20, 2);
    map.setLocation(10, 0, 0);
    map.setProperty("Latitude", 40.54);
    map.setProperty("Longitude", -111.76);
    map.setProperty("Zoom", 11.87);

// The map should have asserted a GISNavigator when it was created
Object navigator = model().find("GISNavigator");
if (!navigator)
    return 0;

// Delete any existing points

// Create a point
Object point1 = createinstance(library().find("/GIS/Point"), navigator); = "FlexSim HQ";
point1.setProperty("Latitude", 40.325546989330164);
point1.setProperty("Longitude", -111.67937559702706);

point1.setSize(4, 3, 2);
point1.color =;
point1.setProperty("DrawPoint", 0);

// For point1, use a Processor shape
string shapename = "fs3d\\Processor\\Processor.3ds";
sets(shape(point1), shapename);
double theindex = getshapeindex(shapename);
setobjectshapeindex(point1, theindex);

// Create another point
Object point2 = createinstance(library().find("/GIS/Point"), navigator); = "SLC Airport";
point2.setProperty("Latitude", 40.777322465390746);
point2.setProperty("Longitude", -111.98225326723002);
point2.color =;

// Connect the points to create a route
contextdragconnection(point1, point2, "A");

// Get a reference to the newly created route
treenode routeNode = getvarnode(point1, "routes").last;

// Set its Update Type to Driving Roads and Update it
routeNode.subnodes["updateType"].value = GIS_UPDATE_TYPE_DRIVING_ROADS;
function_s(navigator, "updateRoute", routeNode);

// The route's color is stored on a subnode called colorNode. It will be black if that node has no subnodes.
treenode colorNode = routeNode.subnodes["colorNode"];
while (colorNode.subnodes.length < 3)
    colorNode.subnodes.add().value = 0;
colorNode.subnodes[3].value = 0.7; // blue

// Create a Truck
Object truck = model().find("Truck1");
if (!truck) {
    truck = createinstance(library().find("?TaskExecuter"), model()); = "Truck1";
    string shapename = "fs3d\\FlowItem\\SemiTruck\\";
    sets(shape(truck), shapename);
    double theindex = getshapeindex(shapename);
    setobjectshapeindex(truck, theindex);
    truck.setLocation(10, 10, 0);
    truck.setSize(13.57 * 0.5, 1.88 * 0.5, 2.85 * 0.5);

    // Connecting a TE to a point will connect that TE to the GIS Navigator with that point as its reset point.
    contextdragconnection(truck, point1, "A");

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

Woah, that is a huge script. It sure will help me a lot, thank you very very much.
2 Likes 2 ·

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.