<?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: Pan/Zoom to selected features in Python Add-in in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333368#M25980</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply Mathew.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made some changes to (seemingly) unrelated parts of the script today and somewhere along the line the pan and zoom buttons started working again! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The only (minor) issue now is that zooming to selected features, especially from a small scale, doesn't zoom all the way in on the first click, and if you then click zoom again it'll zoom properly. Sometimes you have to click three times to zoom right in... It's weird, but not a massive problem at the moment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Mar 2014 14:29:43 GMT</pubDate>
    <dc:creator>DanEvans</dc:creator>
    <dc:date>2014-03-12T14:29:43Z</dc:date>
    <item>
      <title>Pan/Zoom to selected features in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333366#M25978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to write a simple Python add-in that provides a combo box allowing the user to enter a project number. They can then click buttons to 'draw' (i.e. select all the pipe features in that project), pan to (select the pipes in the project, then pan to them, keeping the current scale) or zoom to (select the pipes in the project, then zoom to their extent). If the user enters a project number and presses enter, the default behaviour is to just 'draw'/select the pipes in the project.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'draw'/select functionality works fine, either by pressing enter or clicking the button. The pan and zoom to buttons don't pan or zoom though! They do the selection okay, but the view stays in the same extent and scale.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code is below. Any help would be greatly appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import pythonaddins

class DrawProject(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for MRPAssistant_addin.panbutton (Button)"""
&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.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.mapping.ListLayers(mxd, "DistributionMain", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "[MRP_EZRESULTS.PROJECTID] = " + projectsearchcombobox.value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
class PanToProject(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for MRPAssistant_addin.panbutton (Button)"""
&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.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.mapping.ListLayers(mxd, "DistributionMain", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "[MRP_EZRESULTS.PROJECTID] = " + projectsearchcombobox.value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.panToExtent(layer.getSelectedExtent())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

class ProjectSearchComboBox(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for MRPAssistant_addin.projectsearchcombobox (ComboBox)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.items = [""]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editable = True
&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.dropdownWidth = 'WWWWWW'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.width = 'WWWWWW'
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onSelChange(self, selection):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onEditChange(self, text):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global project
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; project = text
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onFocus(self, focused):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onEnter(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.mapping.ListLayers(mxd, "DistributionMain", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "[MRP_EZRESULTS.PROJECTID] = " + project)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def refresh(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass

class ZoomToProject(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for MRPAssistant_addin.zoombutton (Button)"""
&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.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.mapping.ListLayers(mxd, "DistributionMain", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "[MRP_EZRESULTS.PROJECTID] = " + projectsearchcombobox.value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = layer.getSelectedExtent()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 16:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333366#M25978</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2014-03-11T16:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Pan/Zoom to selected features in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333367#M25979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That should work. Are you sure you only have one data frame? If you are getting to the point of the selection working properly I don't see what would be causing these issues. Try removing, recreating, and reinstalling the add-in. Maybe it is still hanging on to an older version.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you getting any error messages?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also try this to see if you get any different behaviour.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;df.zoomToSelectedFeatures()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As a side note, this would be my preferred manner of doing the pan.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;df.extent = df.panToExtent(layer.getSelectedExtent())&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 14:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333367#M25979</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-12T14:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pan/Zoom to selected features in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333368#M25980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply Mathew.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made some changes to (seemingly) unrelated parts of the script today and somewhere along the line the pan and zoom buttons started working again! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The only (minor) issue now is that zooming to selected features, especially from a small scale, doesn't zoom all the way in on the first click, and if you then click zoom again it'll zoom properly. Sometimes you have to click three times to zoom right in... It's weird, but not a massive problem at the moment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 14:29:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pan-zoom-to-selected-features-in-python-add-in/m-p/333368#M25980</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2014-03-12T14:29:43Z</dc:date>
    </item>
  </channel>
</rss>

