I was slapping together a toolbox tool today and came across an interesting issue.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">Toolbox</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">__init__</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""</SPAN>
self<SPAN class="punctuation token">.</SPAN>label <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Toolbox"</SPAN>
self<SPAN class="punctuation token">.</SPAN>alias <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token"># List of tool classes associated with this toolbox</SPAN>
self<SPAN class="punctuation token">.</SPAN>tools <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>Tool<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">Tool</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">__init__</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define the tool (tool name is the name of the class)."""</SPAN>
self<SPAN class="punctuation token">.</SPAN>label <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Tool"</SPAN>
self<SPAN class="punctuation token">.</SPAN>description <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
self<SPAN class="punctuation token">.</SPAN>canRunInBackground <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">MessageBox</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> Title<SPAN class="punctuation token">,</SPAN> Message<SPAN class="punctuation token">,</SPAN> ButtonStyle<SPAN class="operator token">=</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> MessageboxType<SPAN class="operator token">=</SPAN><SPAN class="string token">"NOICON"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""
Raises a system-modal messagebox with the given title and message
with the specified ButtonStyle and MessageboxType. Used to raise
messageboxes from a Python Toolbox tool operating on a Background Thread.
INPUTS:
Title (String)
Title of the messagebox
Message (String)
Message to be displayed in the messagebox
ButtonStyle (Integer)
Value: Buttons Shown:
0 OK (Default)
1 OK | Cancel
2 Abort | Retry | Ignore
3 Yes | No | Cancel
4 Yes | No
5 Retry | No
6 Cancel | Try Again | Continue
MessageboxType (String)
Value: Description:
NOICON No icon is displayed in the Messagebox
INFO An Information Icon is displayed
QUESTION A Question Mark Icon is displayed
WARNING A Warning Icon is displayed
ERROR An Error Icon is displayed
OUTPUTS:
Button Clicked (Integer)
Value returned indicates the buttonpressed by the user
Return Value Button Pressed
1 OK
2 Cancel
3 Abort
4 Retry
5 Ignore
6 Yes
7 No
10 Try Again
11 Continue
"""</SPAN>
<SPAN class="keyword token">if</SPAN> MessageboxType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"NOICON"</SPAN><SPAN class="punctuation token">:</SPAN>
MB_STYLE <SPAN class="operator token">=</SPAN> <SPAN class="number token">0x00</SPAN>
<SPAN class="keyword token">elif</SPAN> MessageboxType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"INFO"</SPAN><SPAN class="punctuation token">:</SPAN>
MB_STYLE <SPAN class="operator token">=</SPAN> <SPAN class="number token">0x40</SPAN>
<SPAN class="keyword token">elif</SPAN> MessageboxType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"QUESTION"</SPAN><SPAN class="punctuation token">:</SPAN>
MB_STYLE <SPAN class="operator token">=</SPAN> <SPAN class="number token">0x20</SPAN>
<SPAN class="keyword token">elif</SPAN> MessageboxType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"WARNING"</SPAN><SPAN class="punctuation token">:</SPAN>
MB_STYLE <SPAN class="operator token">=</SPAN> <SPAN class="number token">0x30</SPAN>
<SPAN class="keyword token">elif</SPAN> MessageboxType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"ERROR"</SPAN><SPAN class="punctuation token">:</SPAN>
MB_STYLE <SPAN class="operator token">=</SPAN> <SPAN class="number token">0x10</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> Exception<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Invalid 'MessageboxType' value"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> ButtonStyle <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> Exception<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Invalid 'ButtonStyle' value"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">import</SPAN> ctypes
buttonPressed <SPAN class="operator token">=</SPAN> ctypes<SPAN class="punctuation token">.</SPAN>windll<SPAN class="punctuation token">.</SPAN>user32<SPAN class="punctuation token">.</SPAN>MessageBoxA<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN>
<SPAN class="punctuation token">,</SPAN> Message
<SPAN class="punctuation token">,</SPAN> Title
<SPAN class="punctuation token">,</SPAN> ButtonStyle <SPAN class="operator token">|</SPAN> MB_STYLE <SPAN class="operator token">|</SPAN> <SPAN class="number token">0x40000</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> buttonPressed
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getParameterInfo</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define parameter definitions"""</SPAN>
param0 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>
displayName<SPAN class="operator token">=</SPAN><SPAN class="string token">"Input Features"</SPAN><SPAN class="punctuation token">,</SPAN>
name<SPAN class="operator token">=</SPAN><SPAN class="string token">"in_features"</SPAN><SPAN class="punctuation token">,</SPAN>
datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"GPString"</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType<SPAN class="operator token">=</SPAN><SPAN class="string token">"Required"</SPAN><SPAN class="punctuation token">,</SPAN>
direction<SPAN class="operator token">=</SPAN><SPAN class="string token">"Input"</SPAN><SPAN class="punctuation token">)</SPAN>
param0<SPAN class="punctuation token">.</SPAN>filter<SPAN class="punctuation token">.</SPAN>type<SPAN class="operator token">=</SPAN><SPAN class="string token">"ValueList"</SPAN>
param0<SPAN class="punctuation token">.</SPAN>filter<SPAN class="punctuation token">.</SPAN>list<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Butter"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Milk"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Bread"</SPAN><SPAN class="punctuation token">]</SPAN>
params <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>param0<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">return</SPAN> params
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">isLicensed</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Set whether tool is licensed to execute."""</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">updateParameters</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""</SPAN>
<SPAN class="keyword token">if</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>value<SPAN class="punctuation token">:</SPAN>
self<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Selected Parameter"</SPAN><SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>valueAsText<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">updateMessages</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">execute</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">,</SPAN> messages<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""The source code of the tool."""</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Parameter 0: "</SPAN> <SPAN class="operator token">+</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>valueAsText<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
There's nothing crazy going on here. Only thing out of the ordinary is that MessageBox function.
Here's the weird thing. My updateParameters function has some logic to raise a Messagebox that displays the value selected by the user in param0. Works fine except that for some reason, the value is being sliced - I'm only getting the first letter of the selected parameter.

I also added an AddMessage function to the execute function to print the selected parameter to the Results Window. That actually gives me the full value, so perhaps it is my Messagebox function that is slicing it but I don't think so.
Anyone have any insight?