Prompting User to Load a file

When using the sample script to select a directory and then prompting the user to select a file to load, the select directory works but upon asking the user to select a file the corresponding dialog does not use the stored directory and the dialog is a SAVE dialog rather than OPEN.

// Prompt for folder to load
DEFINE_VAR NAME="DIR_TO_LOAD" PROMPT="DIR" \
ABORT_ON_CANCEL=NO
LOG_MESSAGE --Directory:%DIR_TO_LOAD%
// Prompt for .shp file to load in folder. Cancel if nothing selected.
DEFINE_VAR NAME="FILE_TO_LOAD" PROMPT="FILE" \
VALUE="%DIR_TO_LOAD%.shp" ABORT_ON_CANCEL=YES
// Load the file.
IMPORT FILENAME="%FILE_TO_LOAD%"

Best Answer

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,026
    Answer ✓
    Hello,

    Add FILE_MUST_EXIST=YES to your DEFINE_VAR command.

    Cheers,
    Bob

Answers

  • Doc2rDoc2r Posts: 21
    Cheers for that Bob, On another not I am trying to trim LAS data to a set of areas that i have split with the SPLIT_LAYER command; the split of the shape file to separate layers works well but when i try to trim the LAS data to each separate feature it fails and selects all the data. Could you kindly have a look at the code below and see if any problem jumps out at you

    GLOBAL_MAPPER_SCRIPT VERSION=1.00

    UNLOAD_ALL
    // Prompt for .las file to load. Cancel if nothing selected.
    DEFINE_VAR NAME="LAS_TO_LOAD" PROMPT_TEXT="Open LAS data file" PROMPT="FILE" VALUE=".las" ABORT_ON_CANCEL=YES FILE_MUST_EXIST=YES
    IMPORT FILENAME="%LAS_TO_LOAD%" TYPE="LIDAR_LAS" \
    ELEV_UNITS="METERS" LABEL_FIELD_FORCE_OVERWRITE="NO" LABEL_FORMAT_NUMBERS="YES" \
    LABEL_PRECISION="-1" LABEL_REMOVE_TRAILING_ZEROS="YES" LABEL_USE_SCIENTIFIC_NOTATION="NO" \
    ALT_MODE="ABSOLUTE" LIDAR_DRAW_MODE_GLOBAL="YES" LIDAR_DRAW_MODE="COLOR" LIDAR_POINT_SIZE="0" \
    LIDAR_DRAW_QUALITY="85" LIDAR_BRIGHTNESS="0" CLIP_COLLAR="NONE"

    // Zoom to extents
    SET_VIEW LAYER_BOUNDS="%LAS_TO_LOAD%"
    // Prompt for .shp file to load in folder. Cancel if nothing selected.
    DEFINE_VAR NAME="FILE_TO_LOAD" PROMPT_TEXT="Open Shape file" PROMPT="FILE" VALUE=".shp" ABORT_ON_CANCEL=YES FILE_MUST_EXIST=YES
    // Load the file.
    IMPORT FILENAME="%FILE_TO_LOAD%"
    // Get only filename of layer without path
    DEFINE_VAR NAME="LOADED_FILENAME" VALUE="%FILE_TO_LOAD%" FILENAME_PIECE="FNAME" 
    LOG_MESSAGE --Loaded File: %LOADED_FILENAME%
    // Split layer by channel node ID attribute
    SPLIT_LAYER FILENAME="%FILE_TO_LOAD%" SPLIT_BY_ATTR="bnid" 
    // Prompt to continue
    DEFINE_VAR NAME="CONTINUE" PROMPT_TEXT="CONTINUE" PROMPT="YES_NO"
    IF COMPARE_STR="%CONTINUE%=NO"
    FORCE_EXIT CLOSE_APP=NO
    END_IF
    // Loop through all the open layers, better if could limit to shape file group
    LAYER_LOOP_START FILENAME="*" 
    //Seems to limit to just the shape files
    IF COMPARE_STR="%LOADED_FILENAME%<%LAYER_DESC%"
    //Show layer being processed
    LOG_MESSAGE --Processing Layer: %LAYER_DESC%
    //Crop LAS data to feature on current layer being processed
    EDIT_LIDAR FILENAME="%LAS_TO_LOAD%" POLYGON_CROP_FILE="%LAYER_DESC%" POLYGON_CROP_USE_EACH=YES POLYGON_CROP_BBOX_ONLY=NO NEW_LAYER_NAME="%LAYER_DESC%" 
    // Prompt to continue
    DEFINE_VAR NAME="CONTINUE" PROMPT_TEXT="CONTINUE" PROMPT="YES_NO"
    IF COMPARE_STR="%CONTINUE%=NO"
    FORCE_EXIT CLOSE_APP=NO
    END_IF
    END_IF
    LAYER_LOOP_END


    Also is there a way to move the data directly to the layer being processed rather than it creating another layer with the same name? Or to merge the layers with identical names?

    Any help would be appreciated.
Sign In or Register to comment.