Encrypt and decrypt a script document using Avenue

Last Published: April 25, 2020


The first script in this article uses a character replacement scheme to write an encrypted version of a script document to a text file. The second script reverses the encryption to recreate the original script.


  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Rename the script "Encrypt."

    A. Select Properties from the Script menu.
    B. Type in a new name in the Name field.
    C. Click OK.

  3. Copy the following code into the new window:

    '-- Encrypt TextFile
    '-- Back up scripts before encrypting. Use the script key
    '-- to unencrypt the scripts.
    '-- Back up this script, change password and encrypt this script.

    theScript = av.GetActiveDoc
    theDelete = theScript
    theFName = av.GetProject.MakeFileName("scrpt", "ave")

    theFName = FileDialog.Put( theFName, "*", "Write Script")
    if (nil = theFName) then

    f = LineFile.Make(theFName, #FILE_PERM_WRITE)
    if (f = nil) then
    msgbox.error("Cannot open file:"++theFName.GetName, "")

    if (theScript.GetSelected.Count = 0) then
    '-- Change the order of the second parameter in
    '-- translate to set your own key. Use all 26 letters
    '-- only once in random order, then do the same to key
    theKey = theScript.GetSource.translate(
    theScript = theKey
    av.ShowMsg( "Script written to"++theFName.GetFullName )
    av.ShowMsg( "Selected text written to"++theFName.GetFullName )

    if (System.GetOS = #SYSTEM_OS_MAC) then
    Script.Make("MacClass.SetDocInfo(SELF, SEd)").DoIt(theFName)

  4. Open another new script window.
  5. Rename the script "Unencrypt."
  6. Copy the following code into the new script window:

    '-- Encrypt TextFile Key
    '-- Back up this script, change password and encrypt this script.

    theTest = MsgBox.Password
    thePass = "esri"
    if (theTest = thePass) then
    theSEd = av.GetActiveDoc
    file_names = FileDialog.ReturnFiles({"*.ave", "*"},
    {"Avenue Script", "Text file"}, "Load Script", 0)
    if (file_names.count < 1) then exit end
    IsEncrypt = MsgBox.YesNo("Is Script Encrypted?", "Encrypted?", TRUE)
    if (isEncrypt = TRUE) then
    for each x in file_names
    f = TextFile.Make(x, #FILE_PERM_READ)
    t =
    v = t.translate("zyxwvutsrqponmlkjihgfedcba",
    else end
    else MsgBox.Info("PassWord is Incorrect", "Info")

  7. Attach each script to a new button on the Script GUI.

    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog, select Script under Type dropdown.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Enter the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see 'Customize dialog box' in ArcView Help.

  8. Open the script document you wish to encrypt and click the new Encrypt button.

    You must unencrypt the script in order to use it in ArcView. To unencrypt the script click the Unencrypt button and select the file.

Article ID:000004210

  • Legacy Products

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options