English

How To: Change the HOME variable to the location of the active theme

Summary

This script will change the $HOME variable to the location of the active theme in the view. This will work regardless of the theme type. It will not set the variable to a directory that is not writable.

Procedure

  1. Open a new script window.

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

  2. Copy the following code into the script window:

    Code:
    '-- This script is designed to run from either a script window
    '-- or from a button attached to the View GUI.

    '-- Get the view and the theme
    theView = av.GetActiveDoc
    theTheme = theView.GetActiveThemes.Get(0)

    '-- Get the file name and strip out the theme name
    '-- leaving only the directory path
    theSrcName = theTheme.GetSrcName
    theFileName = theSrcName.GetFileName
    theLocation = theFileName.AsString.Substitute(theSrcName.GetName,"")

    '-- Check the directory write permissions.
    '-- If not writeable, let the user select one that is writable.
    '-- Set the HOME variable.
    If (File.IsWritable(theLocation.AsFileName)) then
    System.SetEnvVar("HOME",theLocation)
    Else
    MsgBox.Warning("The directory is not writable"+nl+
    "Please select another directory","Bad Path")
    theString = MsgBox.Input("Path to new home variable:",
    "New Home Variable",System.GetEnvVar("HOME"))
    If ((theString = nil) OR (File.IsWritable(theString.AsFileName).Not)) then
    MsgBox.Info("No changes were made.","")
    Else
    System.SetEnvVar("HOME",theString)
    End
    End

    '-- Display the new path for the HOME variable.
    MsgBox.Info(System.GetEnvVar("HOME"),"Home Variable")

  3. Click the Compile button.
    [O-Image] Script compile button
  4. Do one of the following to run the script:

    Option A
    1. Position the view and script windows such that both are visible.
    2. Make the view and the theme active.
    3. Click directly on the script window.
    4. Click the Run button.
    [O-Image] Run compiled script button
    Option B
    1. Attach script to a button on the GUI.

    A. Activate the Project window.
    B. Select Project menu > Customize.
    C. In the Customize dialog box, select the desired GUI from the Type dropdown list.
    D. Select Category > Buttons.
    E. Click New.
    F. Double-click the Click property in the Customize dialog box.
    G. Enter the name of the desired script in the Script Manager and click Select.
    H. Close the Customize dialog box.

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


    2. Make the view and the theme active.
    3. Click the new button.