1

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")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 17, 2016 at 19:38
1
  • So I've removed the time.sleep() and fixed my indentation. I have to leave pass 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. Commented Aug 19, 2016 at 14:50

1 Answer 1

2

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")
answered Aug 17, 2016 at 23:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.