<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python addin questions - edit existing addin, plus using existing code in addin. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84163#M6653</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Lesson #2 - try with something much less complicated first.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jigged together a quick 'add layer' script which seems to be working ok - which seems to indicate issues with my coding. Will investigate further tomorrow.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Feb 2014 04:09:11 GMT</pubDate>
    <dc:creator>AnthonyCheesman</dc:creator>
    <dc:date>2014-02-04T04:09:11Z</dc:date>
    <item>
      <title>Python addin questions - edit existing addin, plus using existing code in addin.</title>
      <link>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84161#M6651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi - apologies for what is probably a n00b question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've just watched the free seminar on creating Python add-ins for 10.1, and am having a crack at building&amp;nbsp; a custom toolbar to deploy two existing (and working) Python scripts that I am using as part of a custom project.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Neither of the scripts require any user input - it should be just click and go - so they're probably not ideal for an addin, but the attraction is that I can package and deploy them to users relatively easily, plus I get to use custom graphics for the icons, rather than the standard toolbox scrool pic that gets used when you add a tool to a toolbar.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This (as far as I can see) should be as easy as defining the toolbar and tool classes (no need to define the extension, or is there?) and then pasting the code into the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, this doesn't seem to be working for me, as when I load the addin I get [missing] on the tool buttons. The seminar is a bit vague on this, but refers to it probably being a syntax error in the code. I'm pretty sure this isn't the case as both blocks of code work when run independently.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So - questions from me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1/ pasting in existing code: I've deleted the pre-formed definitions and just left def _init_ - does the existing code get indented in line with this, or one step in?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2/ do I even need the def _init_ definition, or can I bin it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3/ Is there a limit on the sizes of the icon graphics (16x16 pixels rings a bell)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4/ Final stupid question - how on earth do you go back and edit an existing add-in - or do you just start again from scratch?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import pythonaddins

class ExportGPSlog(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for AerialTrackingGPSlog_addin.gpstool (Tool)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Existing code block pasted in here

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Export GPSlog to Dropbox
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Written for Getac V200 Aerial Tracking Project
&amp;nbsp;&amp;nbsp;&amp;nbsp; # leftieant 4 Feb 2014

&amp;nbsp;&amp;nbsp;&amp;nbsp; # import libraries

&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; from arcpy import env
&amp;nbsp;&amp;nbsp;&amp;nbsp; import socket
&amp;nbsp;&amp;nbsp;&amp;nbsp; import time
&amp;nbsp;&amp;nbsp;&amp;nbsp; from time import localtime, strftime
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp;&amp;nbsp; # set environment parameters

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r'D:\gis\aerialtracking'
&amp;nbsp;&amp;nbsp;&amp;nbsp; ws = arcpy.env.workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; computername = socket.gethostname()
&amp;nbsp;&amp;nbsp;&amp;nbsp; dropboxloc = "\\Dropbox\\output\\"

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Check if gpslog exists

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Checking if GPSlog geodatabase exists."

&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("\\data\\GPSlog.gdb\\pointlog"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "GPSlog geodatabase and pointlog GPS log both exist."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "GPSlog geodatabase and/or pointlog GPS log do NOT exist."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exiting script."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(5)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit()

&amp;nbsp;&amp;nbsp;&amp;nbsp; # check if pointlog contains features or is empty

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Checking to see if pointlog contains any features to export."
&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; if int(arcpy.GetCount_management("\\data\\GPSlog.gdb\\pointlog").getOutput(0)) == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "GPS log is empty, therefore no features to export."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exiting script."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit()

&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "GPS log contains " + str(arcpy.GetCount_management("\\data\\GPSlog.gdb\\pointlog")) + " feature(s)."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "These features will now be exported to the Dropbox location."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create datetime &amp;amp; PC-named stamped folder in \Dropbox\output

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating custom folder for GPS log export."
&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; savetime = strftime("%Y%m%d_%H%M", localtime()) #this is the current time for the folder stamp
&amp;nbsp;&amp;nbsp;&amp;nbsp; foldername = computername + "_" + savetime + "_hr_GPSlogexport"
&amp;nbsp;&amp;nbsp;&amp;nbsp; exportfolder = ws + dropboxloc + foldername
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not os.path.exists(exportfolder): os.makedirs(exportfolder)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #export GPSlog.gdb/pointlog to exportfolder

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exporting contents of GPS log to shapefile in custom folder."
&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToShapefile_conversion("\\data\\GPSlog.gdb\\pointlog",exportfolder)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Export complete."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Export failed."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(5)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clear out GPSlog

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleting all features from source GPSlog."

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteFeatures_management("\\data\\GPSlog.gdb\\pointlog")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "All features deleted from source log."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Log is now clean and ready for more data collection."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print #blankline
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Process complete."

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Unable to delete features from source log."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Script failed."

&amp;nbsp;&amp;nbsp;&amp;nbsp; # delete variables

&amp;nbsp;&amp;nbsp;&amp;nbsp; del ws, computername, dropboxloc, savetime, foldername, exportfolder

class ExportPNGscreenshot(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for AerialTrackingPNG_addin.xstool (Tool)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.

&amp;nbsp;&amp;nbsp;&amp;nbsp; # existing code block pasted in here

&amp;nbsp;&amp;nbsp;&amp;nbsp; # export view to png file
&amp;nbsp;&amp;nbsp;&amp;nbsp; # leftieant 15 August 2013
&amp;nbsp;&amp;nbsp;&amp;nbsp; # This script exports the data view to a .png file (syncs via Dropbox account)

&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os
&amp;nbsp;&amp;nbsp;&amp;nbsp; from arcpy import env
&amp;nbsp;&amp;nbsp;&amp;nbsp; from time import localtime, strftime

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set workspace

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r'd:\gis\aerialtracking\output'
&amp;nbsp;&amp;nbsp;&amp;nbsp; ws = arcpy.env.workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; if str(os.path.exists(ws)) == "False":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ws)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set time variable and print output variable

&amp;nbsp;&amp;nbsp;&amp;nbsp; printtime = strftime("%Y%m%d_%H%M", localtime())
&amp;nbsp;&amp;nbsp;&amp;nbsp; print printtime
&amp;nbsp;&amp;nbsp;&amp;nbsp; pngname = ws +"\\mapexport_" + printtime + "hr.png"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print pngname

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set mxd

&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0] #[0] pulls the first item out of the list

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export PNG

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, pngname, df, df_export_width = 1600, df_export_height = 1200, world_file = False)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #delete variables

&amp;nbsp;&amp;nbsp;&amp;nbsp; del ws, printtime, pngname, mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 02:11:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84161#M6651</guid>
      <dc:creator>AnthonyCheesman</dc:creator>
      <dc:date>2014-02-04T02:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python addin questions - edit existing addin, plus using existing code in addin.</title>
      <link>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84162#M6652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Lesson #1 learnt - use 'button' not 'tool'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still not working though...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 02:59:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84162#M6652</guid>
      <dc:creator>AnthonyCheesman</dc:creator>
      <dc:date>2014-02-04T02:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python addin questions - edit existing addin, plus using existing code in addin.</title>
      <link>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84163#M6653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Lesson #2 - try with something much less complicated first.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jigged together a quick 'add layer' script which seems to be working ok - which seems to indicate issues with my coding. Will investigate further tomorrow.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 04:09:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-addin-questions-edit-existing-addin-plus/m-p/84163#M6653</guid>
      <dc:creator>AnthonyCheesman</dc:creator>
      <dc:date>2014-02-04T04:09:11Z</dc:date>
    </item>
  </channel>
</rss>

