ArcMap 10.4, Windows 7, Python 2.7.10
I am currently working on a python add-in extension that will join a feature class layer with a feature service layer whenever the mxd is opened. When I take the script I have and run it in the python window it joins the two layer perfectly. When I make it into an add-in extension it fails to execute. I have run a test with a text file and it is running the script when the mxd is opened but not the part I need. I tried adding in a timer so it would execute after the mxd is fully up and running but still nothing. I have made this into a toolbar and you can execute when you press the button but this is not ideal. This is being made for people who use arc map to view our database but have basic knowledge and may forget or mess things up.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> pythonaddins
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">JoinRoads</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Implementation for RoadsScript_addin.extension2 (Extension)"""</SPAN>
<SPAN class="keyword token">def</SPAN> openDocument <SPAN class="punctuation token">(</SPAN>self<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>
self<SPAN class="punctuation token">.</SPAN>enabled <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">startup</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">pass</SPAN>
<SPAN class="comment token"># Local variables:</SPAN>
Roads_2015 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Roads 2015"</SPAN>
Roads_2015__2_ <SPAN class="operator token">=</SPAN> Roads_2015
All_roads <SPAN class="operator token">=</SPAN> <SPAN class="string token">"private\\transportation_FA_wa\\All roads"</SPAN>
time<SPAN class="punctuation token">.</SPAN>sleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Process: Add Join</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddJoin_management<SPAN class="punctuation token">(</SPAN>Roads_2015<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BRUCE_ID"</SPAN><SPAN class="punctuation token">,</SPAN> All_roads<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BRUCE_ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_ALL"</SPAN><SPAN class="punctuation token">)</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>