ArcGIS 10.6 tools working on my computer but not another one

292
2
04-05-2020 01:41 AM
StéphaneNguyen
New Contributor

Good morning,

I'm new in this community forum (And also in ArcGIS, been only a few weeks I started), so if I need to add more informations, ask me. The problem doesn't come from my PC so it can take some times because I need to contact the chief of the project.


So my problem is:
I made 2 python scripts for an add-in and toolbox but none of them work on his pc. I tried to search on internet about how to solve this issue.

The first script is only calling Contour and fails directly (Errors: 999999 and 010067) and the second one is calling multiple functions of ArcGIS:
The second script is failing on the function called Union.

I asked him to:

- check if all the extensions are enabled -> it is

- check if it was due to him using a GeoDatabase or not, he then tried without the GeoDatabase, it didn't work.
- he tried Contour from the application ArcMap but it still works with the same file.

The zip file contains the whole code for the add-in and toolbox.

Thank you for your time.

error999999‌ arcgis10.6‌ error010067‌ #arcgis toolbox#python addin

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

the database was not found... error

suggests that there is some path that is being looked for in the script that doesn't exist on his computer.

Downloading a zip and unzipping is a security issue for many,

If the script is not massive, copy and paste the code 

https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting

StéphaneNguyen
New Contributor
"""
Raster to classified polygons:

Transform a raster into polygons with classified attributes. Only 2 classes,
one above the sea level, one under the sea level.
"""



# Import first the arcpy functions for python
import arcpy, os
from arcpy import env
from arcpy.sa import *
import pythonaddins

import tempfile, shutil

arcpy.AddMessage("IMPORTANT: Please don't interrupt even if it takes a long time.")

#https://docs.python.org/3/library/tempfile.html
# Need to manually cleanup.
TMPpath= tempfile.mkdtemp(prefix="TMP",dir=os.path.dirname(__file__))

# Temporary files
outputTmp = os.path.join(TMPpath, "TMPPolygon.shp") # for raster to polygon
outLayerTmp = os.path.join(TMPpath, "TMPLayer.shp") # For Feature class to Feature Layer.
outputUnionTmp = os.path.join(TMPpath, "TMPUnion.shp") # For Union

arcpy.AddMessage("Created TMP Folder and files. If error or interruption, please remove them manually")
################################ Fetching the parameters ################################

# To fetch the parameters from the tool, you need to use the arcpy.GetParameterAsText()
# function. The number inside the brackets indicates which parameter you will get.
# You fetch the input parameters and the output parameters the same way.

inRaster = arcpy.GetParameterAsText(0) # Raster.
sea_level = arcpy.GetParameterAsText(1) # Sea level as baseContour
outputPolygons = arcpy.GetParameterAsText(2) # For polygons

# For raster to classified polygons,
# we set the raster, sea_level and outputPolygons using the inputs (and output)
# parameters of the tool and we manually set the contour interval.

# Check extension.
arcpy.CheckOutExtension("Spatial")

################################ Calling the functions ################################
# I follow the same procedure as described in my gitlab (French)
# https://gitlab.unige.ch/mit_gcm/project/-/tree/master/Classification%2FManual

#-------------------------------------------------------------------------------------
# Multiply by 1000 to be able to use the other functions because the other functions
# need "integer raster" as input.
outTimes = Times(inRaster, 100) # https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/times.htm
# Don't save it .

ELEVATION=int(float(sea_level)*100) # sea_level * 100

#-------------------------------------------------------------------------------------
# Reclassify the outTimes using elevation/sea_level -> Still a raster
# https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/reclassify.htm

# Before doing it, we need the minimum and maximum values of the raster:
#https://gis.stackexchange.com/questions/175352/how-to-get-max-and-min-from-a-raster-using-arcpy
minRaster = arcpy.GetRasterProperties_management(outTimes, "MINIMUM").getOutput(0) # careful it's still multiplied by 100.
maxRaster = arcpy.GetRasterProperties_management(outTimes, "MAXIMUM").getOutput(0)

# Because it has a problem of , instead of . for float..
# https://community.esri.com/thread/170917

minRaster=int(float(minRaster.replace(',','.')) )#-757661
maxRaster=int(float(maxRaster.replace(',','.')) )#503611



# More informations :https://desktop.arcgis.com/fr/arcmap/10.3/tools/data-management-toolbox/get-raster-properties.htm
# https://desktop.arcgis.com/fr/arcmap/latest/tools/spatial-analyst-toolbox/reclassify.htm
# Now reclassify using RemapRange:
arcpy.AddMessage("0/5: Reclassifying Modified Raster..")
outReclass = Reclassify(outTimes, "Value",
RemapValue([[minRaster,ELEVATION, 0],[ELEVATION,maxRaster, 1]])) #Only 2 classes

arcpy.AddMessage("1/5: Reclassifying Modified Raster.. DONE")
# Class 1 : Upper the sea-level.


# Now change it into polygons using Raster to Polygon:
arcpy.AddMessage("1/5: Reclassified Raster to Polygons..")
arcpy.RasterToPolygon_conversion(outReclass, outputTmp, "NO_SIMPLIFY")
arcpy.AddMessage("2/5: Reclassified Raster to Polygons.. DONE")
# instead outputPolygons, use temporary files. Need to remove all of them
# after finishing.

# "Cleaning polygons", creating one layer of continent.

# outLayerTmp is a feature layer
arcpy.AddMessage("2/5: Feature class to Feature layer..")
arcpy.MakeFeatureLayer_management(outputTmp, outLayerTmp, '"gridcode"=1') # only over the ocean level
arcpy.AddMessage("3/5: Feature class to Feature layer.. DONE")

#arcpy.SelectLayerByAttribute_management(outputTmp, 'NEW_SELECTION', '"gridcode"=1')
arcpy.AddMessage("3/5: Union/Removing Gaps..")
arcpy.Union_analysis(outLayerTmp, outputUnionTmp, gaps=False) #no GAPS !!
arcpy.AddMessage("4/5: Union/Removing Gaps..DONE")

# Aggregate polygons (We will lose the gridcode column)
# Dissolve(in_features, out_feature_class, {dissolve_field}, {statistics_fields}, {multi_part}, {unsplit_lines})
arcpy.AddMessage("4/5: Dissolving polygons..")
arcpy.Dissolve_management(outputUnionTmp, outputPolygons)
arcpy.AddMessage("5/5: Dissolving polygons/Merging.. DONE")

#https://stackoverflow.com/questions/1557351/python-delete-non-empty-dir
# Extremely dangerous, better to remove one by one later.
shutil.rmtree(TMPpath,ignore_errors=True)
try:
os.rmdir(TMPpath)
arcpy.AddMessage("Removed TMP directory")
except OSError as error:
arcpy.AddMessage("Cannot remove TMP directory")


# I need to do this later: https://docs.python.org/3/library/signal.html
# in case of signals.. need to remove the folder.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I'm not sure to understand if I need to edit my post or post like this. This is biggest script above. Below, it's the script for Contour:

# coding: utf-8

# Import first the arcpy functions for python
import arcpy
from arcpy import env
from arcpy.sa import *
import pythonaddins

################################ Fetching the parameters ################################

# To fetch the parameters from the tool, you need to use the arcpy.GetParameterAsText()
# function. The number inside the brackets indicates which parameter you will get.
# You fetch the input parameters and the output parameters the same way.

input = arcpy.GetParameterAsText(0)
sea_level = arcpy.GetParameterAsText(1)
output = arcpy.GetParameterAsText(2)

################################ Calling the function ################################

# To call the function you need to specify the parameters. For this function,
# we set the raster, base contour (contour height) and out contour using the inputs (and output)
# parameters of the tool and we manually set the contour interval.

inRaster = input
contourInterval = 10000
baseContour = sea_level
outContour = output

# We then call the function using the parameters previously defined
Contour(inRaster, outContour, contourInterval, baseContour)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And the last code is the addin file.

import arcpy
import pythonaddins

import os
# Link the toolbox with the add-in using relative path.
# The add-in or the toolbox shouldn't be moved somewhere else.
relativePath = os.path.dirname(__file__)
toolboxPath = os.path.join(relativePath, "MITgcmPlus.tbx")

# Each class can be a button or combox etc.

class ButtonClass17(object):
"""Implementation for MITgcmPlus_addin.button_1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
# Calling the toolbox
pythonaddins.GPToolDialog(toolboxPath, "RasterToClassifiedPolygons")


class ButtonClass3(object):
"""Implementation for MITgcmPlus_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
# Calling the toolbox
pythonaddins.GPToolDialog(toolboxPath, "Contour")

class ComboBoxClass4(object):
"""Implementation for MITgcmPlus_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["item1", "item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
pass
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
pass‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

"suggests that there is some path that is being looked for in the script that doesn't exist on his computer." : Do you know a way (know a post) to show more informations about the errors ?
Thank you

0 Kudos