AnsweredAssumed Answered

Arcmap Python Add-in extention will not run on open

Question asked by Rowilkes on Oct 13, 2016
Latest reply on Nov 10, 2016 by LukeW

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.

 

import arcpy
import pythonaddins

class JoinRoads(object):
       """Implementation for RoadsScript_addin.extension2 (Extension)"""
       def openDocument (self):
             def __init__(self):
                   self.enabled = True
       def startup(self):
                   pass
             # Local variables:
Roads_2015 = "Roads 2015"
Roads_2015__2_ = Roads_2015
All_roads = "private\\transportation_FA_wa\\All roads"

time.sleep(30)
             # Process: Add Join
arcpy.AddJoin_management(Roads_2015, "BRUCE_ID", All_roads, "BRUCE_ID", "KEEP_ALL")

 

Outcomes