MapInfo Pro

 View Only
  • 1.  How to take advantage of SmartTexts in the Layout and Layout Templates

    Employee
    Posted 08-31-2018 08:43

    Last week I did a Quick-Fire Tips & Tricks session on SmartText.

    If you didn't attend, you can still watch the recorded session here:

    https://event.on24.com/eventRegistration/EventLobbyServlet?target=reg20.jsp&referrer=https%3A%2F%2Fwcc.on24.com%2Fwebcast%2Fgroupregistration%2F1780214&eventid=1780214&sessionid=1&key=BE94C9CF0D4D09531DEBF53DE51CD4C5&regTag=316181&sourcepage=register&cid=Social_Global_Software_MapInfo_N/A_Registrations_28082018

    I did cover a number of examples so I thought it would be useful to also share the syntax of these samples here in writing.

    SmartText Aliases

    Let's start with the SmartText aliases. As I said in the webinar, these are stored in a dedicated file. This file will be created the first time, MapInfo Pro comes across an Alias in a layout window that it needs to look-up to find the MapBasic expression or string to substitute the alias with.

    The file, SmartTextAliases.xml, is located here, once it has been created: %appdata%\MapInfo\MapInfo\Professional\1700

    As you can see in the image below, it holds a list of aliases and their matching fixed string or MapBasic expression.

    See Attachment

    You can add your own additional aliases if you want to. And you should of course change some of the fixed values to match your name and organisation.

    Creating a SmartText in the Layout

    There is two ways to create SmartText in the Layout:

    1. Use an Alias from the SmartTextAliases.xml file
    2. Enter any MapBasic expression

     

    Alias

    You create a SmartText using an Alias by writing the Alias Name inside ${}. So to use the Author alias from the file above, you'll have to write: ${Author}.

    When you edit the text, you'll see the SmartText "expression". When you skip the edit mode, you'll will see the resulting string, in this specific case my name, "Peter Horsbøll Møller"

    See Attachment

    Using the Aliases is quite simple once you get familiar with the available aliases.

    MapBasic expressions

    You create a SmartText using a MapBasic expression by writing the expression inside $mb{}. So to use the Time(24) expression, you'll have to write: $mb{Time(24)}.

    And similar to aliases, you only see the SmartText expression when you edit the text. Otherwise you'll see the resulting string.

    See Attachment

    And as the example above shows, you can easily combine fixed text with the SmartText elements.

    Some other SmartText samples

    During the webinar, I gave a few other examples of SmartTexts that could prove useful, especially in Layout Template so that for example the header information is populated more or less automatically.

    If you want to use the MapBasic expression directly in the layout which you can, remember to wrap them in this text: $mb{}.

    Map Title

    I had created a SmartText alias that referred to the title of the Map in a specific frame. The MapBasic expressional of this SmartText is:

    WindowInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 1)

    And the Alias in the SmartTextAliases file looks like this:

     <Alias name="TitleOfMap-1" description="The window name of the map in the frame named Map-1.">WindowInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 1)</Alias>

    Notice that it refers to the map in the frame called Map-1. This means that you need to make sure that you have named you frame with the map, Map-1. You can do this via the Frame Properties dialog.

    See Attachment

    Current Workspace

    Another useful SmartText was the name of the current workspace. This could be used to easily locate the workspace used to generate the output (paper map or PDF document).

    The MapBasic expression is:

    GetCurrentWorkspacePath$()

    And the SmartText alias in the SmartTextAliases file looks like:

     <Alias name="CurWorkspace" description="Current workspace path and file name.">GetCurrentWorkspacePath$()</Alias>

    Map Coordinate System Name

    You can also create an expression that will show the name of the coordinate system of a map in a specific frame. The frame is here called Map-1.

    The MapBasic expression looks like this:

    MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 18)

    And the line for the SmartTextAliases file:

     <Alias name="CoordsysOfMap-1" description="The coordsys name of the map in the frame named Map-1.">MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 18)</Alias>

    See Attachment

    Using custom MapBasic functions

    I ended the webinar with showing you have you could use custom MapBasic functions in a running MapBasic application. In my example I was using one of the functions in the WindowHelper x64 tool. The function is called MAPHGetCoordinate.

    It takes two parameters:

    • The ID of the Map window to get the coordinate from
    • A string ID specifying which coordinate to return, center x/Y, minimum X/Y or maximum XY. The IDs are CENTX, CENTY, MINX, MINY, MAXX, and MAXY.

     

    The SmartText expression will currently look like this:

    Center: $mb{FormatNumber$(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTX"))} | $mb{FormatNumber$(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTY"))}

    See Attachment

    When we release MapInfo Pro 17.0.1 and the WindowHelper gets updated, the expression will be shortened to this:

    Center: $mb{FormatNumber$( MAPHGetCoordinate( LayoutItemWinID( CurContext(1), "Map-1", 1), "CENTX")} | $mb{FormatNumber$( MAPHGetCoordinate(LayoutItemWinID( CurContext(1), "Map-1", 1), "CENTY")}

    I hope you have found this helpful. I have included my current SmartTextAliases.xml below in case you want to take advantage of some of my aliases.

    Do let us know some good examples of how you are using the SmartText feature.

    Attachment(s)

    xml
    SmartTextAliases.xml   3 KB 1 version


  • 2.  RE: How to take advantage of SmartTexts in the Layout and Layout Templates

    Posted 08-31-2018 07:47

    Thanks @Peter Horsbøll Møller? 

    Already had requests for the map centre. Is it possible to have the map centre co-ordinates as a smart text alias item? I have just tried this but notice that it relies on WindowHelper running first (is that correct?)?



  • 3.  RE: How to take advantage of SmartTexts in the Layout and Layout Templates

    Employee
    Posted 08-31-2018 08:43

    Great question, John. There is a couple of options here.

    1. Use MapperInfo

    The MapperInfo() function can be used without the need of specific tools running in the background. It's easy and simple to use.

    But it also comes with a drawback: it will show the coordinates using the coordinate system of the current session and not via the coordinate system of the map window.

    2. Use WindowHelper

    The custom made function in WindowHelper allows you to extract a number of coordinates from a specific map window: minimum, maximum and the center coordinates.

    The coordinates are always delivered via the coordinate system of the map and they will change if you change the coordinate system.

    However, you need to have WindowHelper running for the expression to work.

    The SmartText Aliases for the two options

    These four lines can be inserted into the SmartTextAliases file and then you can use the defined aliases here instead of the long-winded MapBasic expressions.

     <Alias name="CentXOfMap-1" description="The maximum X coordinate of the map in the frame named Map-1.">MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 3)</Alias>

     <Alias name="CentYOfMap-1" description="The maximum Y coordinate of the map in the frame named Map-1.">MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 4)</Alias>

     <Alias name="CentXOfMap-1WH" description="The center X coordinate of the map in the frame named Map-1.">FormatNumber$(Round(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTX"), 1))</Alias>

     <Alias name="CentYOfMap-1WH" description="The center Y coordinate of the map in the frame named Map-1.">FormatNumber$(Round(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTY"), 1))</Alias>

    I have also included the modified SmartTextAliases file where both these two options have been included.

    Here you can see the result of the three different SmartText expressions for the center coordinate of the map:

    1. The MapBasic expression using WindowHelper described in the initial post
    2. The Alias using the MapperInfo() function described above
    3. The Alias using WindowHelper where the coordinates also are rounded to nearest integer value.

    See Attachment

    Attachment(s)

    xml
    SmartTextAliases.xml   3 KB 1 version


  • 4.  RE: How to take advantage of SmartTexts in the Layout and Layout Templates

    Posted 09-05-2018 12:24

    @Peter Horsbøll Møller?  This is an awesome post. Thanks for this :)



  • 5.  RE: How to take advantage of SmartTexts in the Layout and Layout Templates

    Employee
    Posted 09-05-2018 12:29
    Thanks, @Krishna Bejawada, glad to hear you like it