Python GP Package

312
2
06-24-2012 10:42 PM
ShaunWeston
Occasional Contributor
I'm running into an issue when packaging up a python script. In the script it adds a field and then calculates the field like this:

# Calculate Fields
arcpy.CalculateField_management(SelectedStrategy_Loss, "Before_nLoss", "[urineNLeached]", "VB", "")

This all works fine when I run it in ArcGIS Desktop as a tool, however after I package up this process, I notice the following is done at the top of my script:

# Esri start of added variables
import os, arcpy
g_ESRI_variable_1 = os.path.join(arcpy.env.packageWorkspace,u'data.gdb\\Strategies\\Strategies_Polygon')
g_ESRI_variable_2 = os.path.join(arcpy.env.packageWorkspace,u'data.gdb\\Strategies\\Strategies_Line')
g_ESRI_variable_3 = os.path.join(arcpy.env.packageWorkspace,u'data.gdb\\Strategies\\Strategies_Point')
g_ESRI_variable_4 = os.path.join(arcpy.env.packageWorkspace,u'data.gdb\\Nitrogen')
g_ESRI_variable_5 = u'%scratchGDB%\\SelectedStrategy'
g_ESRI_variable_6 = u'%scratchGDB%\\SelectedStrategyLoss'
g_ESRI_variable_7 = u'Before_nLoss'
g_ESRI_variable_8 = u'"urineNLeached"'
g_ESRI_variable_9 = u'After_nLoss'
g_ESRI_variable_10 = u'"Before_nLoss" * 0.91'
# Esri end of added variables

So, the packaging process seems to be converting the square brackets to quotation marks - u'"urineNLeached"'. When I change this to u'[urineNLeached]', it workd fine.

Just wondering if this is a bug and if it what the workaround would be?
Tags (2)
0 Kudos
2 Replies
ShaunWeston
Occasional Contributor
Alright! Managed to fix it be changing the FieldCalculator to use python instead of VB (makes sense!) and the gp packager kept the exclaimation marks as exclaimation marks:

arcpy.CalculateField_management(SelectedStrategy_Loss, "Before_nLoss", "!urineNLeached!", "PYTHON_9.3", "")
g_ESRI_variable_8 = u'!urineNLeached!'
0 Kudos
KevinHibma
Esri Regular Contributor
Shaun,

Any chance you could send me your original tool in a zip file and data necessary to run it?
The packaging of script tools does do variable substitution as you have discovered, however it should always run once it becomes a GPK.
If you're seeing an instance where that isn't the case I want to understand why.

If you're able to share, please send to khibma[@]esri.com

thanks
0 Kudos