ArcGIS, Python and File Exists

November 26, 2008

I use the script in models to test to see if output exists, if it exists, delete the files.  Otherwise do nothing.  Rather than include coding in my models for when the file does not exist, I have been create a “Step 2″ model.  I prefer creating multiple small models so that I can get each step working.  Someone asked, “Why not recombined once all the steps work?”  My answer is that I still find it easier to keep everything compartmentalized in case I want to tweak latter or try to streamline coding.

fileexists1

#**********************************************************************
# Description:
# Tests if a Dataset/Feature Layer and outputs two booleans:
#   Exists – true if the Dataset exists, false if it doesn’t exist
#   Not_Exists – true if the Dataset doesn’t exist, false if it does exist
#                (the logical NOT of the first output).
#
# Arguments:
#  0 – DataSet Name
#  1 – Exists (boolean – see above)
#  2 – Does Not Exists (boolean – see above)
#
# Created by: ESRI
# Modified By Mike Wilson (3/28/08)
#**********************************************************************

# Standard error handling – put everything in a try/except block
#
try:

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Get input arguments – DataSet Name
#
in_Dataset = gp.GetParameterAsText(0)

# First check that the DataSet exists
#
if gp.Exists(in_Dataset):
gp.SetParameterAsText(1, “True”)
gp.SetParameterAsText(2, “False”)
else:
gp.SetParameterAsText(1, “False”)
gp.SetParameterAsText(2, “True”)

# Handle script errors
#
except Exception, errMsg:

# If we have messages of severity error (2), we assume a GP tool raised it,
#  so we’ll output that.  Otherwise, we assume we raised the error and the
#  information is in errMsg.
#
if gp.GetMessages(2):
gp.AddError(GP.GetMessages(2))
else:
gp.AddError(str(errMsg))
#**********************************************************************

I modified this script quite a while ago and use it often.  I believe it is based on the “Field Check script” and the article “Branching: Implementing if-then-else logic“.  I apologize for note being more specific, but I misplaced my notes.  If I have improperly cited the origin, let me know.  I coded this prior to my start of using Evernote.


Layout Server Object Extension and Print Layout Task Install guide with Notes

November 22, 2008

Layout Server Object Extension and Print Layout Task Install guide for a 2 System Setup

via Print Layout Task / Server Object Extension for .NET Web ADF (manual install)

The system I am setting this Extension up on is a 2 machine AGS system as illustrated below:

agssetup

(From http://edndoc.esri.com/arcobjects/9.1/ArcGISServer/HelpPages/Server_typical.gif)

I found this led to some difficulties getting the scripts running and have tried to make notes.  All added notes are in bold. (Original Material from Author markdeaton)

Installing the Layout Server Extension (SOC):

1. Copy LayoutSOE.dll into the machine

2. Register with regasm /codebase /tlb (Details about this at the end of the
doc in the ‘About Registering Assemblies’ section)

3. Add the assembly to the GAC with gacutil /i (Details about this at the end of the
doc in the ‘About Registering Assemblies’ section)

Installing the Layout Server Extension Property Page (Desktop admin):
This machine is where you plan to use ArcCatalog to administer AGS.  It can be any machine with ArcCatalog in stalled, including the webserver or SOM box.

4. Close ArcCatalog on and ArcGIS Desktop machine

5. Make sure ArcGIS Server is up and running.

6. Make sure you are logged as an ArcGIS Server admin (User account used must be in AGSAdmin group on SOM/SOC box).

7. Copy LayoutSOE.dll into the machine

8. Register with regasm /codebase /tlb(Details about this at the end of the
doc in the ‘About Registering Assemblies’ section)

9. Add the assembly to the GAC with gacutil /i (Details about this at the end of the
doc in the ‘About Registering Assemblies’ section)

10. Copy LayoutSOEPropPage.dll into the machine

11. Register with regasm /codebase /tlb (Details about this at the end of the
doc in the ‘About Registering Assemblies’ section)

12. Restart ArcGIS Server. (I stopped and Started via Windows “Services”)

Installing the Print Task (webServer):

1. Copy LayoutSOETask.dll in the webServer.

2. Copy LayoutSOE.dll in the webServer

3. Register both assemblies with regasm /codebase /tlb

4. Add the assembly to the GAC with gacutil /i

5. Run UpdateManager.exe passing true to install and false to uninstall.
UpdateManager will make sure that the print task is recognized by ArcGIS
Manager and that the task will look like any other task in any application
created with Manager (style will match the template you choose).

UpdateManager.exe is run from the cmd prompt:

cmd

In cases where you are not using the default web server directory open the code for the “UpdateManager”.  Look for the following code in “Program.cs”:

namespace UpdateManager
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine(“Must pass true or false”);
Console.WriteLine(“Press any key to continue…”);
Console.ReadLine();
return;
}
Console.WriteLine(“Finding IIS Root Folder…”);
string root = findIISRoot();
if (root == “”)
{
Console.WriteLine(“Error”);
Console.WriteLine(“  Cannot find IIS root folder. Is IIS installed in the machine?”);
Console.WriteLine(“Press any key to continue…”);
Console.ReadLine();

return;            }

Change:

string root = findIISRoot();

To match correct path and rebuild project:

string root = @”f:\inetpub\wwwroot” //findIISRoot();

Replace UpdateManager.exe with rebuilt pjoject

6. Restart IIS.

Getting started:
Open Readme_ArcScripts.doc and follow the Script.  I found that with our current setup, The “Layout SOE” could not be added via AGS Manager.  It could only be added via a custom web application in Visual Studio 2005.

Adding the task to custom web applications (web server):

13. Create a new webApp with Manager and add the mapService that has the
layoutSOE extension enabled. Make sure that the mapService as added via
an AGS Local Connection.

14. Add the ArcGIS Identity to the webApp.

In cases where you cannot change ArcGIS Identity from VS 2005, save the project and change settings on he webserver.  On the webserver go to “Internet Information Services” -> Right Click on your WebApp -> Click “Properties” -> Click on “ASP.Net” tab -> Click on “Edit Configuration”-> Click on “Applications” and Check “Local Impersonation” and add username and password.  User and password need to be members on AGSUsers group on all machaines and have identical passwords.
asp

15. Open default.aspx in design mode with visual studio.

16.Add the task assembly (LayoutSOETask.dll) to the toolbox by right
clicking the toolbox; selecting ‘choose items’ and browsing to the
assembly (LayoutSOETask.dll). The next image shows the LayoutSOETask
once added to the toolbox in Visual Studio.

clipboard03

17. Drag the task from the toolbox into the taskManager (“TaskManager1″) control.

18. Set the Task Results Panel property (a dialog will show up automatically)

clipboard05

clipboard06

19. Push F4 with the LayoutSOETask control selected to open it’s properties.

properties
Make sure that the properties dialog is opened for the LayoutSOETask
control, and not the TaskManager control.

20. In the Properties dialog, go to the ‘resources’ category and set the
MapControlID (the map), then set the resourceName to the service added
in step #2. If this list is empty make sure that you have added an AGS
Map Service with the LayoutSOE capability enabled, AND that this map
service is AGS Local Resource.  I found that in some cases, initially the resource with the Layout SOE enabled under the”MapResourceName” was not avaialble.  To solve this click on “MapControlID” and reselect the map.

clipboard07

21. Also change the visible property of the LayoutSOETask control to false. Otherwise the task will always be visible by default without even opening it. when the application starts.

About Registering Assemblies:
Regasm registration
Go to Start-All Programs- Microsoft .Net Framework 2.0 – SDK Command Prompt
Type: regasm full_path_to_the_assembly /codebase /tlb
For example
Regasm D:\Demos\Layout\LayoutSOE.dll /codebase /tlb
Gacutil registration
Type gacutil /i full_path_to_the_assembly

Note: This document was created by people who have used this utility in the past. If you
have any suggestions-improvements on this document please contact the author so the
document can be updated.  Need a way to contact the Author.