<?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: Generating a centroid for a polygon in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195265#M5067</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;James, I am trying to create an Add-In following this link:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;But I cannot find ArcGIS node under project type. What do I need to do in order to get that in Visual Studio?&lt;/STRONG&gt;&lt;BR /&gt;I apologise for these questions as I am a bit of a beginner in Arc.&lt;BR /&gt;&lt;BR /&gt;I will be adding this to ArcMap and hopefully, once it is up and running, my colleagues will be using it too.&lt;BR /&gt;Thanks.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I *think* this is because you do not have the ArcGIS .NET SDK ("Developer Kit") installed.&amp;nbsp; Can someone else confirm this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Oct 2011 13:19:14 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2011-10-13T13:19:14Z</dc:date>
    <item>
      <title>Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195261#M5063</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;SPAN&gt;I am trying to help my colleague who wants to select a polygon and then click a button, which would generate a centroid for that polygon. Ideally, he wants a pop-up to appear which would display a copy&amp;amp;pasteable X and Y. He wants this automation as he wants X and Y to be generated for polygons using the same algorithm.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was thinking of building a custom tool for him using a model. Could anyone please point me to the tools I need in order to achieve this? If you have already written a tool, would you like share it with me? I am quite comfortable in python and VBA but am not so familiar with Arc tools. I would actually prefer to do this in python as the support for VBA won't be there in future.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be extremely appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 10:15:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195261#M5063</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T10:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195262#M5064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if there is a forum specific to Python, but if you are going to write something similar to VBA, you'd probably want either create an Add-In or a COM implementation (I assume this is for extending ArcMap?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any event, here is some code that would get the centroid (and lat/lon values of that centroid) of a selected polygon feature for the first layer in the TOC.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
pDoc = m_pApp.Document
pMap = pDoc.FocusMap

''get the selection from the layer
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = pMap.Layer(0)

Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Decimal 'not sure exactly which number format you'd want to use
Dim lon As Decimal

Dim pFeat As IFeature = pFCursor.NextFeature
Do Until pFeat Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; pPoly = pFeat.ShapeCopy
&amp;nbsp;&amp;nbsp;&amp;nbsp; pArea = pPoly
&amp;nbsp;&amp;nbsp;&amp;nbsp; pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; lat = pPoint.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; lon = pPoint.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFeat = pFCursor.NextFeature
Loop
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this may be a kind of round-about way to get at things, but it does seem to work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195262#M5064</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T09:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195263#M5065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for this. But what do you mean by creating an Add In or COM implementation? Actually, don't answer that. I've found the link and am reading about them now.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 12:47:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195263#M5065</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T12:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195264#M5066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;James, I am trying to create an Add-In following this link:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I cannot find ArcGIS node under project type. What do I need to do in order to get that in Visual Studio?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I apologise for these questions as I am a bit of a beginner in Arc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will be adding this to ArcMap and hopefully, once it is up and running, my colleagues will be using it too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 13:15:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195264#M5066</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T13:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195265#M5067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;James, I am trying to create an Add-In following this link:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;But I cannot find ArcGIS node under project type. What do I need to do in order to get that in Visual Studio?&lt;/STRONG&gt;&lt;BR /&gt;I apologise for these questions as I am a bit of a beginner in Arc.&lt;BR /&gt;&lt;BR /&gt;I will be adding this to ArcMap and hopefully, once it is up and running, my colleagues will be using it too.&lt;BR /&gt;Thanks.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I *think* this is because you do not have the ArcGIS .NET SDK ("Developer Kit") installed.&amp;nbsp; Can someone else confirm this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 13:19:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195265#M5067</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2011-10-13T13:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195266#M5068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I *think* this is because you do not have the ArcGIS .NET SDK ("Developer Kit") installed.&amp;nbsp; Can someone else confirm this?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I need ArcGIS Visual Studio Integration Framework!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any other way I can acheive this? i.e. build a custom tool based on a model?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 13:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195266#M5068</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T13:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195267#M5069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think I need ArcGIS Visual Studio Integration Framework!&lt;BR /&gt;&lt;BR /&gt;Is there any other way I can acheive this? i.e. build a custom tool based on a model?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just fyi, from: &lt;/SPAN&gt;&lt;A href="http://edndoc.esri.com/arcobjects/9.2/NET/73516929-d390-456c-84bc-c8f8a58b645a.htm"&gt;http://edndoc.esri.com/arcobjects/9.2/NET/73516929-d390-456c-84bc-c8f8a58b645a.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"...The ArcGIS Visual Studio IDE Integration Framework is installed as part of the Software Developer Kit (SDK) for .NET for each ArcGIS product and is an optional feature during installation. This framework is available for Visual Studio 2005, Visual Basic 2005 Express, Visual C# 2005 Express, and Visual Web Developer 2005 Express editions."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I am not certain if the VS IDE Framework is what you need.&amp;nbsp; I do believe that the reason why no ArcGIS Project templates show up is because you simply do not have the ArcGIS .NET SDK installed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 13:34:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195267#M5069</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2011-10-13T13:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195268#M5070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;So, I am not certain if the VS IDE Framework is what you need.&amp;nbsp; I do believe that the reason why no ArcGIS Project templates show up is because you simply do not have the ArcGIS .NET SDK installed.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, you are right. I have to get it installed in order to try your code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 14:13:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195268#M5070</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T14:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195269#M5071</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 have made a slight amendment to your code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Sub CreateCentroid()

pDoc = m_pApp.Document
pMap = pDoc.FocusMap

Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = pMap.Layer(0)

Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Long
Dim lon As Long

Dim pFeat As IFeature
IFeature = pFCursor.NextFeature
Do Until pFeat Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; pPoly = pFeat.ShapeCopy
&amp;nbsp;&amp;nbsp;&amp;nbsp; pArea = pPoly
&amp;nbsp;&amp;nbsp;&amp;nbsp; pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; lat = pPoint.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; lon = pPoint.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFeat = pFCursor.NextFeature
Loop

End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And I am trying to run this code as a VBA macro but it is failing at this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;pFSelection = pMap.Layer(0)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Compile Error: Method or data member not found.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas as to why is failing here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195269#M5071</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2021-12-11T09:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195270#M5072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First, are you declaring pDoc and pMap somewhere else?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Dim pDoc As IMxDocument
Dim pMap As IMap
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If not, you will need to put these at the top of your CreateCentroid Sub or make them Private variables in the entire class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It has been a long time since working with VBA, but I don't think this will work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

pDoc = m_pApp.Document

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try to replace it with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Dim pDoc As IMxDocument
pDoc = Application.Document 

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195270#M5072</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T09:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195271#M5073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;in VBA you need to do 'set' with a pointer.&amp;nbsp; A pointer is anything not a literal (a literal usually you can write down on a paper).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;set pFSelection = pMap.Layer(0)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The part about declaring the variables is useful too since it avoids all kind of errors, you only need it if you put the option explicit at the top of the class (before any methods.)&amp;nbsp; You should always use option explicit.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 12:19:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195271#M5073</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-10-14T12:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195272#M5074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for all your help so far. I have now amended the code to the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Option Explicit

Sub CreateCentroid()

Dim pDoc As IMxDocument
Dim pMap As IMap

Set pDoc = Application.Document
Set pMap = pDoc.FocusMap

Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
Set pFSelection = pMap.Layer(0)

Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Long
Dim lon As Long

Dim pFeat As IFeature
Set pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoly = pFeat.ShapeCopy
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pPoly
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; lat = pPoint.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; lon = pPoint.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeat = pFCursor.NextFeature
Loop

End Sub

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But now I am getting a run-time error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Run-time error:91 Object Variable or With Block Variable not set&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I click on debug, it takes me to the following line in code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Set pFeat = pFCursor.NextFeature&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195272#M5074</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2021-12-11T09:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195273#M5075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;But now I am getting a run-time error:&lt;BR /&gt;&lt;BR /&gt;Run-time error:91 Object Variable or With Block Variable not set&lt;BR /&gt;&lt;BR /&gt;When I click on debug, it takes me to the following line in code:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Set pFeat = pFCursor.NextFeature&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's probably because you are not setting pFCursor anywhere (I don't think I provided that in my original post.&amp;nbsp; sorry I am picking snippets from my own implementation which is different).&amp;nbsp; See if this helps/completes the code.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Sub CreateCentroid()

Dim pDoc As IMxDocument
Dim pMap As IMap

Set pDoc = Application.Document
Set pMap = pDoc.FocusMap

Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
Set pFSelection = pMap.Layer(0)

&lt;STRONG&gt;pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor 
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)&lt;/STRONG&gt;
Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Long
Dim lon As Long

Dim pFeat As IFeature
Set pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoly = pFeat.ShapeCopy
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pPoly
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; lat = pPoint.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; lon = pPoint.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeat = pFCursor.NextFeature
Loop

End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195273#M5075</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T09:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195274#M5076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The pSelectionSet.Search(Nothing, False, pFCursor) is appearing in red. I am guessing it should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
pFCursor = Nothing
pFCursor = pSelectionSet.Search(Nothing, False, pFCursor)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195274#M5076</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2021-12-11T09:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195275#M5077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The pSelectionSet.Search(Nothing, False, pFCursor) is appearing in red. I am guessing it should be:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
pFCursor = Nothing
pFCursor = pSelectionSet.Search(Nothing, False, pFCursor)
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No the way you have the pFCursor would not work --- the code I posted works just fine for me.&amp;nbsp; I really don't know why it would appear in red or do I even know what that means.&amp;nbsp; I am using Visual Studio 2008 with all of the proper SDK's installed, along with ArcGIS v10.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195275#M5077</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T09:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195276#M5078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also, you have specified the lat and lon variables as LONG data type.&amp;nbsp; Why?&amp;nbsp; This would produce a whole number, which I don't know of any Latitude/Longitude coordinate that is a whole number.&amp;nbsp; Is that what you want?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:29:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195276#M5078</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2011-10-14T13:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195277#M5079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Also, you have specified the lat and lon variables as LONG data type.&amp;nbsp; Why?&amp;nbsp; This would produce a whole number, which I don't know of any Latitude/Longitude coordinate that is a whole number.&amp;nbsp; Is that what you want?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, the reason for that is that I wanted Eastings and Northings instead of latitude and longitude. So I take it that this code produces latitude and longitude? I assumed that lat and lon were just variable names and didn't mean that the code was actually producing latitude and longitude. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The thing is that I am running this as a Macro in the VB editor under Customise menu in ArcMap. And you have access to full visual studio environment. Maybe that's why this is not going to work as a macro. I am trying my best to get hold of VS 2008 or above, in order to install the SDK for .net&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wonder if some one can help us run this as a macro in the mean time!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:43:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195277#M5079</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-14T13:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195278#M5080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In VBA you only use brackets in a method call when you expect a return.&amp;nbsp; In the case of the ISelectionSet.Search, the cursor variable is passed in the method and returns populated.&amp;nbsp; It is one of my peeves with ArcObjects, sometimes the method returns the value you want, other times you have to pass in a variable that gets populated by the function.&amp;nbsp; Both methods are legitimate, I just wish esri picked one and stuck with it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Dim pFCursor as IFeatureCursor
pFCursor = nothing 
pSelectionSet.Search Nothing, False, pFCursor
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195278#M5080</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2021-12-11T09:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195279#M5081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also, after looking at some older posts I noticed for VBA that pDoc should be set to "ThisDocument" instead of how the OP has it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Set pDoc = Application.Document
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should this be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Set pDoc = ThisDocument
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry it's been a long time since I've used VBA and just trying to help out as best I can!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195279#M5081</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T09:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195280#M5082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In VBA, ThisDocument is a shortcut to Application.Document.&amp;nbsp; Both are equivalent.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 14:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/generating-a-centroid-for-a-polygon/m-p/195280#M5082</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-10-14T14:28:38Z</dc:date>
    </item>
  </channel>
</rss>

