<?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: Polygon Centroid in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19871#M1542</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was thinking of using a zoom to centroid approach, since my field has multiple attributes with the same name.&amp;nbsp; Also, if I am in zoomed in working on a feature class, I would use the zoom to centroid of my Subd field, and see the what is left to modify within that Subd area.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Aug 2013 19:02:55 GMT</pubDate>
    <dc:creator>JamesSmith7</dc:creator>
    <dc:date>2013-08-09T19:02:55Z</dc:date>
    <item>
      <title>Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19866#M1537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to create a script that zooms to a polygon centroid.&amp;nbsp; I want the polygon centroid to be based on a Subd attribute field.&amp;nbsp; Location is a feature class and I intend to use the SHAPE@XY to zoom to the polygon centroid.&amp;nbsp; I am receiving an RuntimeError: Invalid SQL statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;centroid = "SHAPE@XY" spatialref = arcpy.Describe("Location").spatialReference cursor = arcpy.da.SearchCursor("Location", "Subd", centroid, spatialref)&amp;nbsp; row[0] = Subd del row del cursor&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 12:03:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19866#M1537</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-08-09T12:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19867#M1538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This seems to give me the SHAPE@XY value of a selected polygon feature in a FGDB FeatureClass I have loaded into ArcMap 10.1 -- ignore the first "if" statement if you are not concerned about checking for GroupLayer data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for sublyr in lyr:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if dsc.shapeType == "Polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(sublyr, "SHAPE@XY")) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(row))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tlyr = lyr&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if dsc.shapeType == "Polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(tlyr, ("SHAPE@XY")) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(row))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:47:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19867#M1538</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-10T20:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19868#M1539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just to extend what James already said, to zoom to the centroid of a feature, you'd likely feed in an Extent based on the centroid xy return you're interested in to the df obj he already established (see his code), then if I'm not mistaken you have to refreshActiveView.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think your trick will be to establish the extent from your point coords...not a big deal, but you need to establish xy min and max, not just a single point coord.&amp;nbsp; Otherwise, there is a zoomToSelectedFeatures, but that'll very likely yield different results for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...even if your extent obj established doesn't quite provide the zoom level you want, you may 'readjust' the scale property, as in DataFrame example 2 on this page:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;DataFrame (arcpy.mapping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Desktop » Geoprocessing » ArcPy » Mapping module&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 15:23:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19868#M1539</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-08-09T15:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19869#M1540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To follow up with Waynes contribution, if all you want to do is zoom to a selected feature -- you could just do that too and not even worry about centroids or extents of anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; for lyr in arcpy.mapping.ListLayers(mxd):&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tlyr = lyr&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dsc = arcpy.Describe(tlyr) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sel_set = dsc.FIDSet &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if dsc.shapeType == "Polygon": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(sel_set) &amp;gt; 0:&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or, if you are still wanting to use the individual rows of the cursor for some reason, you could get the extent of each SHAPE@ value of the row object (this does exactly what the above code does, so I am not sure if it will benefit you. I just thought it is more inline with your OP code):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd):&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tlyr = lyr&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dsc = arcpy.Describe(tlyr) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sel_set = dsc.FIDSet &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if dsc.shapeType == "Polygon": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(sel_set) &amp;gt; 0:&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(tlyr, ("SHAPE@")) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = row[0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zoomextent = shape.extent&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = zoomextent &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 16:48:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19869#M1540</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-08-09T16:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19870#M1541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was thinking of using a zoom to centroid approach, since my field has multiple attributes with the same name.&amp;nbsp; Also, if I am in zoomed in working on a feature class, I would use the zoom to centroid of my Subd field, and see the feature class at another scale.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 19:01:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19870#M1541</guid>
      <dc:creator>JacobDrvar</dc:creator>
      <dc:date>2013-08-09T19:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19871#M1542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was thinking of using a zoom to centroid approach, since my field has multiple attributes with the same name.&amp;nbsp; Also, if I am in zoomed in working on a feature class, I would use the zoom to centroid of my Subd field, and see the what is left to modify within that Subd area.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 19:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19871#M1542</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-08-09T19:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19872#M1543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;...like that a lot, what you did with Describe,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Describe(tlyr).FIDSet&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One of the things I haven't been too fond of is RefreshActiveView -- I don't like 'flashing' the screen unnecessarily, so essentially if there's no selection there's no need to change or refresh the view.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks James, I have to remember that one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oops I tried to delete that duplicate post and both were deleted, sorry.&amp;nbsp; So, relevant info is here in the web help in case you need it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;DataFrame (arcpy.mapping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Desktop » Geoprocessing » ArcPy » Mapping module&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 20:02:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19872#M1543</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-08-09T20:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19873#M1544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to select the polygon, hit a python addin button and zoom to centroid?&amp;nbsp; Or am I required to run the tool by selecting the polygon, entering input parameters, and then zoom to the centroid?&amp;nbsp; I would like to perform the operation without having to enter input parameters.&amp;nbsp; But, I am unsure if Python has this capability.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 11:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19873#M1544</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-08-12T11:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19874#M1545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Is it possible to select the polygon, hit a python addin button and zoom to centroid?&amp;nbsp; Or am I required to run the tool by selecting the polygon, entering input parameters, and then zoom to the centroid?&amp;nbsp; I would like to perform the operation without having to enter input parameters.&amp;nbsp; But, I am unsure if Python has this capability.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, and if that is the workflow you decide on then the df.zoomToSelectedFeatures() will work out just fine.&amp;nbsp; It will zoom to the extent of the selected&amp;nbsp; feature though, not the cetnroid so not sure if that affects your requirement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just code the onClick event of your Python Add-In button:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

class ButtonClass_WorkSelection(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for MyTools_addin.button (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; 
&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; for lyr in arcpy.mapping.ListLayers(mxd):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tlyr = lyr&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dsc = arcpy.Describe(tlyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sel_set = dsc.FIDSet
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(sel_set) &amp;gt; 0:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:47:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19874#M1545</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-10T20:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19875#M1546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I am going with the centroid approach.&amp;nbsp; I took your advice on adding the above script into the add in.&amp;nbsp; But, when clicking on the button, I get the message stating the tool has no parameters.&amp;nbsp; I have been unable to get buttons to work without input parameters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 12:35:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19875#M1546</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-08-12T12:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19876#M1547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes, I am going with the centroid approach.&amp;nbsp; I took your advice on adding the above script into the add in.&amp;nbsp; But, when clicking on the button, I get the message stating the tool has no parameters.&amp;nbsp; I have been unable to get buttons to work without input parameters.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What are the parameters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also try to simplify the script (untested):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&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; df.zoomToSelectedFeatures()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:47:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19876#M1547</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-10T20:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19877#M1548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;String attribute fields.&amp;nbsp; If I select the polygon, enter the input parameters, the script selects and zooms to the polygon centroid.&amp;nbsp; But, without the input parameters, the button does not work.&amp;nbsp; I was thinking Python required input parameters, since scripts are similar to tools run from ArcToolbox.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 12:43:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19877#M1548</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-08-12T12:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19878#M1549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
 for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp; tlyr = lyr&amp;nbsp;&amp;nbsp; 
&amp;nbsp; dsc = arcpy.Describe(tlyr)
&amp;nbsp; sel_set = dsc.FIDSet
&amp;nbsp; if dsc.shapeType == "Polygon":
&amp;nbsp;&amp;nbsp; if len(sel_set) &amp;gt; 0:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(tlyr, ("SHAPE@")) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zoomextent = shape.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(lyr.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = zoomextent
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
except:
 print arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:47:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19878#M1549</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2021-12-10T20:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19879#M1550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have modified the suggestions provided to only zoom to one selected Feature Class.&amp;nbsp; But, I want to return the AddMessage line if the correct Feature Class is not selected.&amp;nbsp; The script does not get to the else statement for other Feature Classes.&amp;nbsp; When a Fields polygon is selected, the script zooms to the polygon extent.&amp;nbsp; But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected.&amp;nbsp; So, why does the script not use the else statement for Feature Classes other than Fields?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0]&lt;BR /&gt;for fds in arcpy.mapping.ListLayers(fds):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fds)&lt;BR /&gt; type = desc.shapeType&lt;BR /&gt; if type == "Polygon":&lt;BR /&gt;&amp;nbsp; df.extent = fds.getSelectedExtent()&lt;BR /&gt; else:&lt;BR /&gt;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 11:35:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19879#M1550</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-15T11:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon Centroid</title>
      <link>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19880#M1551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have modified the suggestions provided to only zoom to one selected Feature Class. But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. When a Fields polygon is selected, the script zooms to the polygon extent. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0]
for fds in arcpy.mapping.ListLayers(fds):
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fds)
&amp;nbsp;&amp;nbsp;&amp;nbsp; type = desc.shapeType
&amp;nbsp;&amp;nbsp;&amp;nbsp; if type == "Polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = fds.getSelectedExtent()
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:47:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/polygon-centroid/m-p/19880#M1551</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2021-12-10T20:47:39Z</dc:date>
    </item>
  </channel>
</rss>

