HOW TO
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.
Code:
'-- 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
exit
end
f = LineFile.Make(theFName, #FILE_PERM_WRITE)
if (f = nil) then
msgbox.error("Cannot open file:"++theFName.GetName, "")
exit
end
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(
"abcdefghijklmnopqrstuvwxyz",
"zyxwvutsrqponmlkjihgfedcba")
theScript = theKey
f.WriteElt(theScript)
av.ShowMsg( "Script written to"++theFName.GetFullName )
else
f.WriteElt(theScript.GetSelected)
av.ShowMsg( "Selected text written to"++theFName.GetFullName )
end
f.close
if (System.GetOS = #SYSTEM_OS_MAC) then
Script.Make("MacClass.SetDocInfo(SELF, SEd)").DoIt(theFName)
end
av.GetProject.RemoveDoc(thedelete)
Code:
'-- 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 = f.read(f.GetSize)
v = t.translate("zyxwvutsrqponmlkjihgfedcba",
"abcdefghijklmnopqrstuvwxyz")
theSEd.Insert(v)
f.Close
end
else end
else MsgBox.Info("PassWord is Incorrect", "Info")
end
Note:
You must unencrypt the script in order to use it in ArcView. To unencrypt the script click the Unencrypt button and select the file.
Get help from ArcGIS experts
Download the Esri Support App