Global Mapper v25.0

Batch Command Scripting

AndreaR
AndreaR Global Mapper UserTrusted User
edited July 2014 in GM Script Language
Hi Mike,

Excuse my continously request, but GM is super, i want to finish my project, and i hope that this exchange of information can help any other people that use Global Mapper, to undestand the scripting language.

I noticed from your help, that with an external application i can run one script, GM execute it, and when processed exit from GM.

For now I did some test only with a file .bat:

I created a DOS file named RUN_SCRIPT.bat with only this command:
"C:\Program Files\GlobalMapper15_64bit\global_mapper.exe" "OSM_SCRIPT_IN_PROGRESS.gms"

I launch RUN_SCRIPT.bat and i see that the file is processed, because in my GM script file there is a command that write some files in a folder, and i can check that the files are created!

But when i launch my RUN_SCRIPT.bat, if i want to check if GM is already opened and auto run my script in the contest of the Main View is possible that? I not able to find a documentation for this!

If this is not currently possible, the best would add the option parameters like this (is only an example):

"C:\Program Files\GlobalMapper15_64bit\global_mapper.exe" /L /T "OSM_SCRIPT_IN_PROGRESS.gms"

L = Force to Open a new instance of Global Mapper also if GM is already opened and execute the script in the context of the Main View.

T = Test if Global Mapper is already opened, not open other instance, and execute the script in the context of the Main View.

An alterative is to add (if there aren’t already present) a scripting language command at the start of any file script like:

EXECUTE_SCRIPT command with parameters:

SET_CONTEXT=”YES” (default or missing “NO”) for set, if any people lost to set flag in the script windows (File -> Run Script..), run script in the contest of the Main View (this is a parameter that you can add for example to SET_OPT command).

CHECK_ISTANCE=”YES” (default or missing) run script without launch another instance of Global Mapper (only if SET_CONTEXT=”YES” is present).

CHECK_ISTANCE=”NO” launch another instance of Global Mapper and run the script (only if SET_CONTEXT=”YES” is present).

Thanks

Andrea

Comments

  • Geo
    Geo Global Mapper User Trusted User
    edited June 2014
    hello AndreaR,

    take a look at this thread: add start time to script
    and at the sample.bat in post #7
    you will be able to detect if a process is running from your batch file.

    PS:
    the latest archived view of the page "Process Viewer for Windows"
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited June 2014
    Hi Geo,

    I saw your post..

    The problem is running the script via batch, directly in in the contest of the Main View.
    And for check the process, the best would be if it is directly supported by Global Mapper, without write many bach DOS code.

    Thanks for help

    Andrea
  • Geo
    Geo Global Mapper User Trusted User
    edited June 2014
    hello AndreaR,

    do you want Global Mapper not to exit when the script file completes processing and check the results in the user interface when you use the command line?

    to check the process outside GlobalMapper, the command SET_LOG_FILE might be useful.

    how will it be possible to pass as a parameter which running instance of GlobalMapper the script must use ?

    did you know that if an instance of Global Mapper is running and you drag and drop in the user interface the script you want to process, any errors will be displayed in a message box?

    Richard.
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited June 2014
    Hello Richard,

    Thanks for you help

    But my goal is only run a batch command (stored in a DOS .bat) called by another external program (like VB), that if Global Mapper is already open simply execute one script, in the same manner to go manual in File -> Run Script... with flag on the opton "in the context of the Main View", and if Global Mapper is not open, launch it and simply execute the script in the context of main Map View.

    I noticed that for now is not possible to do this! But only run script with any batch command stored for example in .bat file, for log, control an istance, execute many other command that you want, but always out of the main context of main Map View.

    But Mike certainly can help us if there is a way to do this with batch.

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited June 2014
    Andrea,

    If you name your script as .gmw rather than .gms then it will automatically load and run in the context of the main map view rather than running in batch mode. A GMW (Global Mapper Workspace) is a script file, just the file extension controls the behavior when passed on the command line.

    I think doing that may get everything that you want!

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Hi Mike,

    Sorry but i've a problem:
    If i launch this batch command:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw"

    Global Mapper Start and load the file.gmw correctly.
    At this point i send this other command:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova2.gmw"

    but start another instance of Global Mapper and i've two session opened: one with prova.gmw and other with prova2.gmw

    There is a way for run two or more command like:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw"
    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova2.gmw"
    etc..

    And have only one session of Global Mapper opened with both files loaded in two layer?

    Thanks in advanced

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    There is an option in the Advanced section of the General tab of the Configuration dialog to 'Open New INstance When Open File from Explorer'. If you uncheck that and close GM (saving the settings to the registry), then does your command-line sequence keep everything in a single instance?

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Mike,

    Is already unchecked... not work and open another instance for any:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw"

    that i launch from cmd.exe (Win 8.1 pro 64bit)

    I tryed now with Global Mapper 15.2.6 (b070414) 64bit

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    It turns out .gms and .gmw files are treated differently and always load in a new instance. I have added support for adding -existing to the command line and that should force the workspace to load in an existing running instance rather than starting a new one. So use:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw" -existing

    I have placed new builds with the latest changes at the links below:

    32-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15.zip
    64-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15_64bit.zip

    Simply download the .zip file for the build that you are using and extract over your existing installation files. The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper15
    64-bit: C:\Program Files\GlobalMapper15_64bit

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Hello Mike,

    It work well but i've another thing to ask you for have the perfect work.
    When i pass the second and other command with:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw" -existing
    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova1.gmw" -existing
    etc...

    Obviously, Global Mapper for any gmw ask me:

    Would you like to unload all data prior to loading the workspace file?
    YES - Unload all data
    NO - Load workspace on top of loaded data.

    There is a way to add another parameter in command line for automatically choose always: NO - Load workspace on top of loaded data, to avoid the same question every time?

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    I have added support for a new command line parameter, -no_prompt, that you can add to skip the UNLOAD_ALL prompt at the beginning of the workspace when loading a .gmw in to an existing instance.

    I have placed new builds with the latest changes at the links below:

    32-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15.zip
    64-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15_64bit.zip

    Simply download the .zip file for the build that you are using and extract over your existing installation files. The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper15
    64-bit: C:\Program Files\GlobalMapper15_64bit

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Great job Mike,

    Thanks it work very well

    Andrea
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Hi Mike,

    It seems that the UNLOAD_LAYER command does not work anymore.

    The UNLOAD_ALL command work well.

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    I assume it was just not working with hidden layers? I've fixed that now.

    I have placed new builds with the latest changes at the links below:

    32-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15.zip
    64-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15_64bit.zip

    Simply download the .zip file for the build that you are using and extract over your existing installation files. The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper15
    64-bit: C:\Program Files\GlobalMapper15_64bit

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Hi Mike,

    I have one file named PROVA.gmw with this code:
    GLOBAL_MAPPER_SCRIPT VERSION="1.00" FILENAME="D:\PROVA.gmw"
     
    UNLOAD_LAYER FILENAME="LIVELLO_PUNTI.txt"
     
    DEFINE_PROJ PROJ_NAME="GEO_WGS84"
    Projection     GEOGRAPHIC
    Datum          WGS84
    Zunits         NO
    Units          DD
    Xshift         0.000000
    Yshift         0.000000
    Parameters
    0 0 0.00000 /* longitude of center of projection
     
    END_DEFINE_PROJ
    IMPORT_ASCII FILENAME="D:\LIVELLO_PUNTI.txt" PROJ_NAME="GEO_WGS84" \
         TYPE="POINT_ONLY" COORD_DELIM="SEMICOLON" COORD_FORMAT="DECIMAL" COORD_ORDER="Y_FIRST" \
         INC_COORD_LINE_ATTRS="YES" COL_HEADERS="YES" INC_ELEV_COORDS="NO" CREATE_AREAS_FROM_LINES="NO" \
         SKIP_COLUMNS="0" SKIP_ROWS="0" ELEV_UNITS="METERS" LABEL_FIELD_FORCE_OVERWRITE="NO"
    

    And I've an ascii text file named LIVELLO_PUNTI.txt with 10 points inside

    If i launch for the first time PROVA.gmw by command line:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw" -existing -no_prompt

    Global Mapper Start and create a layer named LIVELLO_PUNTI.txt correctly with 10 points.

    Now i add by hand 20 points in LIVELLO_PUNTI.txt and resend:

    C:\programmi\globalmapper15_64bit\global_mapper.exe "E:\prova.gmw" -existing -no_prompt

    The problem is that Global mapper not recognize inside PROVA.gmw file the command:

    UNLOAD_LAYER FILENAME="LIVELLO_PUNTI.txt"

    and instead to unload the old LIVELLO_PUNTI.txt with 10 points, and create another layer named LIVELLO_PUNTI.txt with 20 points, simply add the new LIVELLO_PUNTI.txt

    So in Overlay Control Center instead of one layer with the 20 points i've got two layers:

    LIVELLO_PUNTI.txt[10 Features]
    LIVELLO_PUNTI.txt[20 Features]

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    Ah the -no_prompt flag was skipping the first UNLOAD_ALL or UNLOAD_LAYER. I've updated it to only skip the first UNLOAD_ALL and not do anything special with UNLOAD_LAYER command.

    I have placed new builds with the latest changes at the links below:

    32-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15.zip
    64-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15_64bit.zip

    Simply download the .zip file for the build that you are using and extract over your existing installation files. The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper15
    64-bit: C:\Program Files\GlobalMapper15_64bit

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • AndreaR
    AndreaR Global Mapper User Trusted User
    edited July 2014
    Hello Mike,

    Now it works but i've another question!

    When i launch for the first time:

    C:\programmi\globalmapper15_64bit\global_mapper.ex e "E:\prova.gmw" -existing -no_prompt

    obviously the layer LIVELLO_PUNTI.txt is not yet loaded, and when Global Mapper try to unload it give me a:

    Warning: Unable to unload overlay LIVELLO_PUNTI.txt

    There is a way by scripting language to check if a layer named LIVELLO_PUNTI.txt not exist, and skyip the following UNLOAD_LAYER command?

    Thanks

    Andrea
  • global_mapper
    global_mapper Administrator
    edited July 2014
    Andrea,

    I've added support for adding SHOW_WARNINGS=NO to the UNLOAD_LAYER command. If you add that then you won't get a warning if there is no layer matching FILENAME to unload.

    I have placed new builds with the latest changes at the links below:

    32-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15.zip
    64-bit: http://www.bluemarblegeo.com/downloads/global-mapper/global_mapper15_64bit.zip

    Simply download the .zip file for the build that you are using and extract over your existing installation files. The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper15
    64-bit: C:\Program Files\GlobalMapper15_64bit

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • RobertR
    RobertR GlobalMapper Fan! Trusted User
    edited July 2014
    Nice forum post(s).

    Great to see that many people use the GMScripting tool.