Thanks for the feedback all. You represent it as being obvious and strait forward, which it should be but it simply does not work. Darren, I have recreated your simple add in exactly and sometimes it installs correctly and shows up in extensions, others not. Seems like it depends on how I tilt my head. I've gotten to where I take it all the way back to the Addin Assitant every time since it seems like things get hung when I try to make in line changes.
Here is the current iteration of what I'm actually trying to accomplish. If I input say, the newDocument() function directly into the ArcMap immediate window it does exactly what it is supposed to. If I install it as an add in it never shows up in the extensions.
This repoints layers from an old server to a new one.
import arcpy
import pythonaddins
import os
class serverUpdater(object):
"""Implementation for Server_Updater_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def newDocument(self):
connections = my directory
modeling_PROD1 = sde connection
PROD1_connection = os.path.join(connections,modeling_PROD1)
counter = 0
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES") and lyr.serviceProperties['Server'] == "BESDBTEST1":
print lyr.name
name = lyr.dataSource.split(".")[-1]
lyr.replaceDataSource(PROD1_connection,"SDE_WORKSPACE", name)
print "Replaced source for: " + lyr.name
counter = counter + 1
if counter > 0:
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
pythonaddins.MessageBox("BESDBTEST1 sources have been re-sourced to BESDBPROD1; see python window for details","SERVER SOURCE UPDATE",0)
def openDocument(self):
connections = my directory
modeling_PROD1 = sde connection
PROD1_connection = os.path.join(connections,modeling_PROD1)
counter = 0
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES") and lyr.serviceProperties['Server'] == "BESDBTEST1":
print lyr.name
name = lyr.dataSource.split(".")[-1]
lyr.replaceDataSource(PROD1_connection,"SDE_WORKSPACE", name)
print "Replaced source for: " + lyr.name
counter = counter + 1
if counter > 0:
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
pythonaddins.MessageBox("BESDBTEST1 sources have been re-sourced to BESDBPROD1; see python window for details","SERVER SOURCE UPDATE",0)
UPDATE
- I got it to show up in the Extensions but when I attempt to run it through the event (open/newDocument) I get...nothing. The way I got it to at least show up in Exentions was to drop it into pyScripter instead of Notepadd ++ which gave me different syntax errors regarding indentation. Had to unindent and re-indent back to, as far as I could tell, the exact same spot but it cleaned it up. Anyway, I'm done with trying for the event extension. I set it up to run from a button instead which works.
My 2 cents: Add ins Extensions are majorly broken in their current configuration. There is absolutely no error handling whatsoever for extensions from what I saw. I at least got minimal error messaging when working on the button. Testing consists of attempting to run it, seeing nothing happen, then going back to the script for a round of randomly guessing what could be the issue. I would not recommend this tool to anyone. I've sunk a ridiculous amount of time into doing something that at its face should be strait forward.
Thanks to everyone who attempted to help.