Checking System Information to set ArcToolbox Paths?

635
8
10-03-2011 10:53 AM
MikeMacRae
Occasional Contributor III
Hey everyone,

I am trying to find a way to check my computer system information in order to set correct paths to the Arctoolbox using the older geoprocessor.

I have 2 computers:

One is my Windows XP Pro 32bit OS (version 5.1.2600).
The second is a Windows 7 64bit OS (version 6.1.7601).

I want to do a system check in order to set the correct path to ArcToolbox before the script continues to process.

I thought the following script would do this for me, but when I run it on the second computer (the second if statement or the windows 7 computer) I get a fatal error and ArcCatalogue closes. If I ran it on the first computer, the script runs find. If I were to reverse the if statements, the second computer will always crash in a fatal error. I've used an elif for the second computer, same result. I used an "else: pass" in the first statement, I get the same error.

I figured there should be an easy way to do a system check for the new Programs (x86) system path, but I'm not sure how to do it. Any suggestions?


import arcgisscripting, sys, platform
# Create the geoprocessor object
gp = arcgisscripting.create()

### Load required toolboxes...
##gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes/Data Management Tools.tbx")
##gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes/Analysis Tools.tbx")
# Load required toolboxes (Win7)

if platform.version() == '5.1.2600':
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")

if platform.version() == '6.1.7601':
    gp.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbos("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
Tags (2)
0 Kudos
8 Replies
MathewCoyle
Frequent Contributor
I use this

username = getpass.getuser()
if platform.version()[0] == "6":
    #Check if Windows 7
    sde = "C:\Users\\"+username+"\\AppData\\Roaming\\ESRI\\Desktop10.0\\ArcCatalog\\wisprod.sde"
elif platform.version()[0] == "5":
    #Check if Windows XP
    sde = r"C:\Documents and Settings\\"+username+"\Application Data\ESRI\ArcCatalog\wisprod.sde"

        print "SDE connection found, continuing"
    else:
        "User <"+username+"> is invalid, not found, or you do not have access to SDE."
0 Kudos
MikeMacRae
Occasional Contributor III
Hey Matt,

I've tried your script and edited as follows:

if platform.version()[0] == "6":
    #Check if Windows 7
    gp.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbos("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
elif platform.version()[0] == "5":
    #Check if Windows XP
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")

    print "Connection found, continuing"
else:
    "No connection."


I'm still getting a fatal error. I've also tried this and I'm getting a fatal error as well. I'm not sure what's causing it:

if arcpy.Exists("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes"):
    gp.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbos("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
elif arcpy.Exists("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes"):
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
0 Kudos
MathewCoyle
Frequent Contributor
Did you try this?

if platform.version()[0] == "6":
    #Check if Windows 7
    gp.AddToolbox(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbos(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
elif platform.version()[0] == "5":
    #Check if Windows XP
    gp.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
    gp.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")

    print "Connection found, continuing"
else:
    "No connection."
0 Kudos
MikeMacRae
Occasional Contributor III
Wow, what a whirlwind this one was. I spent all day trying to troubleshoot this and I noticed my problem. If you see the examples I posted above, one of my gp.ArcToolbox syntaxes had one of them spelled 'ArcToolbos'. This created a fatal error and closed ArcCatalogue/ArcMap every time I ran it. I'm not used to fatal errors for simple spelling mistakes. Usually I get a python error/message.

Anyways, the logic was working, apparently my brain wasn't. Thanks for the scripts Matt. I have a  number of old scripts to set up this way, so your examples may come useful.

Mike
0 Kudos
MathewCoyle
Frequent Contributor
Glad I could be of help. Those kind of errors are tough to track down if you don't get a helpful error message.
0 Kudos
AlessandroCinnirella
New Contributor III
you can also use

arcpy.GetInstallInfo("desktop")["InstallDir"]



look at http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003s000000 for the complete documentation

ciao,
AC
0 Kudos
LoganPugh
Occasional Contributor III
I don't think you need to use AddToolbox for standard toolboxes.
0 Kudos
RDHarles
Occasional Contributor
I don't think you need to use AddToolbox for standard toolboxes.


Exactly, there's no need to set anything for standard toolboxes.
I've never put those in any scripts.
0 Kudos