I am using ArcMap 10.4.
I’ve been trying to implement a python add-in that runs when Arcmap is opened.
When the script does run it joins a layer with a feature service layer. I have everything working if you run it in the Arcmap python window. When I take the next step and make it into an add-in it will not work. I added a sleep time to it to delay running until arc is fully open in hopes that it would fix the problem, but no such luck.
I performed a test with a text file and it will update the text file when arc is opened so I know that it is indeed running, it’s just not doing what I want it to. Any ideas?
Here is what I have:
import arcpy
import pythonaddins
class RoadJoin(object):
"""Implementation for RoadJoin_addin.RoadJoin (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
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")
1 Answer 1
Your indentation appears wrong and I am not sure why you have left pass
in there. I also think the time.sleep()
will be unnecessary.
To get further try using:
class RoadJoin(object):
"""Implementation for RoadJoin_addin.RoadJoin (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
# Local variables:
Roads_2015 = "Roads 2015"
Roads_2015__2_ = Roads_2015
All_roads = "private\\transportation_FA_wa\\All roads"
# Process: Add Join
arcpy.AddJoin_management(Roads_2015, "BRUCE_ID", All_roads, "BRUCE_ID", "KEEP_ALL")
time.sleep()
and fixed my indentation. I have to leavepass
in or the script won't run in the Python window. I am still unable to get it to run on start. For a short term workaround I have made the python tool into a toolbar and for now you have to press the button when you open a new arc. It's not ideal but until I can figure this out it will have to do.