Field-Map Scripting

4.4.1.41 Example

Example (Basic)


In the following example, the properties 'Name', 'Layer', 'LayerCount' and 'LayerAtIndex' are used to check if there is a layer with a given name in the Field-Map project. Although it would be straightforward to see for yourself, this might be useful in Field-Map projects where a particular layer is only enabled for certain plots or certain teems of field workers. If the layer is enabled, you might need the script to carry out some extra operations in other layers. If it is disabled, the script does not find it and the extra operations re not carried out.


const

  CHECK_LAYER_NAME = 'TreeLayerForIUFRO';


// on the line above, you can type the name of the layer to be found in the project

var

  i: integer;


begin

  OpenLog('');

  Log('Checking if there is an enabled layer called "' + CHECK_LAYER_NAME + '" in the project "' + Project.Name

    + '"...');

  Log('');

  LogExt('There are ' + IntToStr(Project.LayerCount) + ' currently enabled layers (1 plot layer, 3 hidden layers and ' +

    IntToStr(Project.LayerCount - 4) + ' user-defined)', false);

if Project.Layer[CHECK_LAYER_NAME] = nil then begin Log(', but none of them is called "' + CHECK_LAYER_NAME +

'". See the list of enabled layers:');

for i := 0 to Project.LayerCount - 1 do

begin

      Log(IntToStr(i) + ': ' + Project.LayerAtIndex[i].Name);

end;

end

else

begin

  Log('. The layer with the name "' + CHECK_LAYER_NAME + '" is one of them.');

end;


end.




Example (Synchronization members)


// Example of AfterCreateNewPlot script ...


var

   ID_ :integer;

   tab :TFieldMapTableScriptWrapper;

   CS_ :boolean;

   TypeOfOrganisation_ :integer;


begin


   TypeOfOrganisation_ := InputOptionWithStartingValue('Choose a type of organisation', 'Types of organisation',

                      ['Manufacturing unit','Manipulation storage','Expedition storage'],

                      [1,2,3],

                      1,false);                                                // Users choice of type of new plot


 VS['TypeOfOrganisation_'] := TypeOfOrganisation_;                        


 VS['CodeOfOrganisation'] := ID_;


 VS['Choose'] := 0;


 VS.Post;


  tab := VS.GetLookupTable('Type of organization');                        // Name of new plot is added to lookup list

with tab do

if not Locate('ID',ID_,false,false) then

begin

       Append;

       tab['ID'] := ID_;                

               if ID_=0 then tab['Value1'] := VS['Name']

               else tab['Value1'] := format('%d - %s',[ID_,string(VS['Name'])]);

               tab['Active'] := 1;

       Post;

       end;


 CloseAndFreeTable(tab);  


 Project.PostLookupTablesToSynchroJournal;                                // Modified lookup list structure and content is uploaded to Synchro Journal


end.




See also:

Name; DatabaseType; Version; UserLoginFullName; UserLoginName; UserGroupName; LayerCount; Layer; GetMapLayerListAsXML; ActiveLayer; ActiveLayerName; LayerAtIndex; SysTab_LayerList; SysTab_AttributeList; GetMapLayerListAsXML; ApplyMapLayerList; LoadMapLayerListFromXML; SaveMapLayerListToXML; MapLayerListVisible; SendDataToAnotherRunningProject; GetResourceString; AnotherProjectIsRunning; OpenAnotherProject; BringProjectToFront;SendDataToAnotherRunningProject; OpenInactiveLayers; CloseInactiveLayers; OpenPlot; OpenPlotUsingDataCollector; RunPolyshape; AddLayerWrapper; ScriptsEnabled; OnValidateScriptsEnabled; OnChangeScriptsEnabled; OnChangeTimeStampEnabled; DisableScripts; EnableScripts; RunSynchronization; RunSynchronizationExt; AdjustOnlineCalliperConnection


Example