question

Alyson P avatar image
3 Likes"
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.

FlexSim 21.2.0
flexscriptgiscoordinatesmappoint
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
6 Likes"
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());
    map.name = "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
navigator.subnodes.clear();

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

point1.setSize(4, 3, 2);
point1.color = Color.green;
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);
applyshapefactors(point1);

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

// 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());
    truck.name = "Truck1";
    string shapename = "fs3d\\FlowItem\\SemiTruck\\Truck.ac";
    sets(shape(truck), shapename);
    double theindex = getshapeindex(shapename);
    setobjectshapeindex(truck, theindex);
    applyshapefactors(truck);
    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");
}

repaintall();
· 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.

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