Share
 
 

Exchange Script Examples

This section contains example scripts which provide enough information to carry out exchange of data between an external database and an InfoAsset Manager database using InfoAsset Manager Exchange.

Tip: The example scripts cover the basic functions required to carry out import and export of data. A few other useful functions are outlined at the bottom of this topic. Contact Us for details of more advanced functions.

Additional information about each section of the example script (shown below), can be found in the following sections.

Opening a Database

To exchange data between InfoAsset Manager and an external database, an InfoAsset Manager database has to be open. This corresponds to selecting the database in the main application.

Use WSApplication.open to open an InfoAsset Manager database for import/export.

Either specify the filename for a standalone database or use the form "servername:port/dbname" (as appears in the recently used databases list) for a workgroup database:

db = WSApplication.open(<database>,<boolean>)

Where:

  • database is path of database or nil or ' ' for the last opened database
  • boolean is used internally and should always be set to false

e.g.

db = WSApplication.open('C:\Mydatabase.icmm', false)

Finding a Network

Once the database has been opened, the network within the database with which data is to be exchanged must be identified. This corresponds to clicking on the network object in the tree view in the main application.

Use the model_object_from_type_and_id to find the InfoAsset Manager network for import/export:

nw=db.model_object_from_type_and_id(<name>,<id>)

Where:

  • name is type of network and is 'Numbat Network' for Collection Networks or 'Water Numbat Network' for Distribution Networks.
  • id is the network ID, which can be found in the ID field of the Objects Page of the Properties Dialog in the main application. Right click on the network in the main InfoAsset Manager application and select Properties from the popup menu.

e.g.

nw=db.model_object_from_type_and_id('Collection Network',23)

Import/Export Parameters

Section describing the import and export options to be used. See the following topics for more information:

Reserving a Network

Used when importing to an InfoAsset Manager network.

Update the local copy of the network to the latest version and reserve the network so that no-one else can edit it.

e.g.

nw.reserve

Committing Changes to a Network

Used when importing to an InfoAsset Manager network.

Commit changes to network and unreserve network when commit is finished.

nw.commit(<comment>)

Where:

  • comment is the comment to be saved in the commit history

e.g.

nw.commit('Imported data via csv import')

To commit changes and keep the network reserved, use commit_reserve

e.g.

nw.commit_reserve('Imported data via csv import')

Unreserving the Network

Used when importing to an InfoAsset Manager network.

Remove reserve from the network if an error is encountered. Changes will not be committed.

e.g.

nw.unreserve if nw

Other Useful Functions

This section contains a few functions that users may find useful when using InfoAsset Manager Exchange:

WSApplication

  • set_exit_code(int) sets the return value from the script when it completes.
  • set_working_folder(folder_path) changes the working folder used for the account under which the script runs.
  • override_working_folder(folder_path) changes the working folder for the duration of the current script.
  • use_arcgis_desktop_licence() changes the ArcGIS licence type from ArcGIS Server (the default for InfoAsset Manager Exchange) to the normal desktop licence for the account under which the script runs.

Network

  • uncommitted_changes? returns true if the local copy of the network has uncommitted changes.
  • revert() abandons all uncommitted changes in the local copy of the network.
  • select_clear() clears all selections in the network.
  • select_count() returns the total number of selected objects in the network.

Was this information helpful?