hi guys,
I am using ArcMap 10.5.
I have a tool that adds the name of the location automatically based on the name of the folders (where are located the mxd and the gdb) and the date that has manual input.
The fact, I ran the script in stand-alone and it worked perfectly. However, with the python addin included it doesn't work...
I am sure it works after the "try:" but before it I don't know what am I doing wrong. Please can someone tell what is it.
cheers
Pedro
here is the code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> pythonaddins
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> sys<SPAN class="punctuation token">,</SPAN> string
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env <SPAN class="comment token"># needed for env.workspace definition</SPAN>
<SPAN class="keyword token">import</SPAN> traceback <SPAN class="comment token"># needed to log errors</SPAN>
<SPAN class="keyword token">import</SPAN> datetime
<SPAN class="keyword token">import</SPAN> uuid
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">Island_1_upload</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Implementation for Island_1_addin.combobox (ComboBox)"""</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>
self<SPAN class="punctuation token">.</SPAN>items <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
self<SPAN class="punctuation token">.</SPAN>editable <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
self<SPAN class="punctuation token">.</SPAN>enabled <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
self<SPAN class="punctuation token">.</SPAN>dropdownWidth <SPAN class="operator token">=</SPAN> <SPAN class="string token">'WWWWWWWWWWWW'</SPAN>
self<SPAN class="punctuation token">.</SPAN>width <SPAN class="operator token">=</SPAN> <SPAN class="string token">'WWWWWWWWWWWW'</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">onEditChange</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> text<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">global</SPAN> imageDate
imageDate <SPAN class="operator token">=</SPAN> text
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">onEnter</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> pythonaddins
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> sys<SPAN class="punctuation token">,</SPAN> string
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env <SPAN class="comment token"># needed for env.workspace definition</SPAN>
<SPAN class="keyword token">import</SPAN> traceback <SPAN class="comment token"># needed to log errors</SPAN>
<SPAN class="keyword token">import</SPAN> datetime
<SPAN class="keyword token">import</SPAN> uuid
<SPAN class="keyword token">if</SPAN> any<SPAN class="punctuation token">(</SPAN>char<SPAN class="punctuation token">.</SPAN>isalpha<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> char <SPAN class="keyword token">in</SPAN> imageDate<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>
pythonaddins<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Wrong characters in the date. Please try again!'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Warning'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> len<SPAN class="punctuation token">(</SPAN>imageDate<SPAN class="punctuation token">)</SPAN><SPAN class="operator token"><></SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">:</SPAN>
pythonaddins<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Wrong characters in the date. Please try again!'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Warning'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
startTime <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> startTime
date <SPAN class="operator token">=</SPAN> imageDate
error_code<SPAN class="operator token">=</SPAN><SPAN class="number token">0</SPAN>
<SPAN class="comment token"># Checking the length of string values - if the input parameters defined wrongly, the process will not start</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>date<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><></SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">:</SPAN>
RaiseWarning<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PROBLEM: Wrong date: <"</SPAN><SPAN class="operator token">+</SPAN>date<SPAN class="operator token">+</SPAN><SPAN class="string token">">. It has to be exactly ten characters long."</SPAN><SPAN class="punctuation token">)</SPAN>
error_code <SPAN class="operator token">=</SPAN> error_code <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>strptime<SPAN class="punctuation token">(</SPAN>date<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'%Y/%m/%d'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> ValueError<SPAN class="punctuation token">:</SPAN>
RaiseWarning<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PROBLEM: Wrong date format: <"</SPAN><SPAN class="operator token">+</SPAN>date<SPAN class="operator token">+</SPAN><SPAN class="string token">">. It has to be year/month/day -> yyyy/mm/dd."</SPAN><SPAN class="punctuation token">)</SPAN>
error_code <SPAN class="operator token">=</SPAN> error_code <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="comment token"># mxd and environment; and gdb sources and targets</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>