Field-Map Scripting

4.1.8.7 Example

Example (Global variables):


1. Using the following code snippet illustrates how to make a scripts in your project easily adjustable for possible change of layer names:


In global event AfterOpenProject:


// when a tree layer name changes, this is the only place to change the code

Globals['TreeLayerName'] := 'Trees';


In any other script in the same project:


var

  TreeLayer: TFieldMapTableScriptWrapper;


begin

if Globals.GlobalVariableExists('TreeLayerName') then

    TreeLayer := Project.Layer[Globals['TreeLayerName']]

else

    ShowError('Tree layer not defined in global variables!');


// ...

end.



2. Another example illustrates, how to use global variables to include disabled layers in Database Query Tool Selection window.


In global event BeforeRunDatabaseQueryTool:


begin

    Globals.SetGlobalVariable('IncludeAllInactiveLayers',1);

end.


To include only selected layers use the following expression:


Globals.SetGlobalVariable('IncludeInactiveLayers', 'ExtraLayer; SecondExtraLayer');



3. The next example is useful if you need to run polygonization in Field-Map Data Collector, however, including only selected centroids.


In OnLayer BeforeBuildPolygons event of polygonal layer:


begin

    Globals.SetGlobalVariable('ConsiderSelectedCentrois',1); {0..do not consider; 1..prompt for considering; 2..consider without asking}

end.


When starting polygonization, you will be asked to choose, whether to include all or only selected centroids.


Note: There are more global variables to set the character of polygonization dialogs, e.g.:


    Globals.SetGlobalVariable('SafeCleanLinesAfterPolygonization',1) {0..do not save; 1..prompt for saving; 2..save without asking}

    Globals.SetGlobalVariable('CentroidsSelectionFilter', 'WHERE ID=25') {WHERE + SQL}

    Globals.SetGlobalVariable('IncrementalPolygonization',1) {0..false, change of setting by user enabled; 1..true and enabled; 2..true and disabled; 3..false and disabled}

    Globals.SetGlobalVariable('SkipPolygonizationLayerDialog',1) {0..show dialog by default; 1..do not show dialog}

    Globals.SetGlobalVariable('BackupPriorPolygonization',1) {0..show dialog by default; 1..do not ask user and BACKUP; 2..do not ask user and DON'T BACKUP}

    Globals.SetGlobalVariable('RunPolygonizationWizard',1) {0..No; 1..Yes}


See also:

SetGlobalVariable; GetGlobalVariable; GlobalVariableExists; RemoveGlobalVariable; RemoveGlobalVariables; Value


Example