Macros

What is Macro

Macro is an instrument for launching tasks from the entity context menu, on a graph or a map. Macro executes tasks and enriches your workspace and entities.

Macros in object context menu

Creating a graph macro for your task

A Macro class is used to add macros to the entity context menu. Macro contains a name and instructions on what task to launch and what schemas to create at the task completion.

Macros are returned by get_graph_macros() and get_gis_macros(). If your task has many Macros, create a MacroCollection

Macros will appear in the entity’s context menu only if your task’s enterparams accept one or more of the entity attributes as value source.

In schemas example we described the enterparam MAC address, that can take MAC address attribute as a value source. Let’s take this task and add a macro by overriding the get_graph_macros() method:

def get_graph_macros(self):
    return MacroCollection(
        Macro(name='Vendor lookup', mapping_flags=[GraphMappingFlags.Completely], schemas=[VendorsSchema])
    )
Macro constructor takes 3 required arguments:
  • name is a name for context menu item

  • mapping_flags is more of a Lampyre developer thing. You should always use GraphMappingFlags.Completely for graph macros.

  • schemas is a collection of schemas, that will be added to a graph, from which the macro was called.

Upload this task to Lampyre and create an empty graph by selecting File - New schema. Now navigate to the Instances tab, create an instance of MAC address on a graph and fill it’s attribute with some value. Now when you have an object with a required attribute, you can launch your macro:

The schema, described in this task, contains two objects: MAC address and Vendor. When the request is complete, this schema is deployed on your graph, merging its MAC address object with the existing one, and therefore connecting it to Vendor

GIS macros

GIS macros are much similar to the graph ones, except that they appear in context menus of objects on a map or on this map itself.

To make your task’s macro available for the map context menu, your task must have an enterparam, marked as geojson. If this requirement is fulfilled, you can select a point, figure or line on your map and launch your macro from it’s context menu.

If you want to launch your macro from objects on a map, setup value sources in your task’s parameters just like for the graph macro.

mapping_flags for such macros are listed in GisMappingFlags enumeration.

  • GisMappingFlags.Instances means that the macro will place objects onto a map after its completion

  • GisMappingFlags.Heatmap instructs the macro to create a heatmap based on the count of the objects

  • GisMappingFlags.Path allows creating an object’s path based on the combination of Datetime and Geopoint attributes

Icons for custom objects provided by Icons 8