<?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 Calculate X/Y Using VB or Python in a Model in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164917#M12653</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This VBA script calculates x/y values from the Shape field to another field. It used to work for me in 9.3 but doesn't work anymore for 10 because of the switch to VB/Python. How would I rewrite this in VB or Python to work in 10? The 'Calculate Geometry' function is useless to me because I want to use it in a model and 'Add X/Y' creates new fields rather than calculating existing ones.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Pre-Logic Script Code:
dim dblx as double
dim dbly as double
dim pPoint as Ipoint
set pPoint = [Shape]
dblx = pPoint.x
dbly = pPoint.y


Field=
dbly
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Jul 2011 16:50:18 GMT</pubDate>
    <dc:creator>GabeMarcello</dc:creator>
    <dc:date>2011-07-05T16:50:18Z</dc:date>
    <item>
      <title>Calculate X/Y Using VB or Python in a Model</title>
      <link>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164917#M12653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This VBA script calculates x/y values from the Shape field to another field. It used to work for me in 9.3 but doesn't work anymore for 10 because of the switch to VB/Python. How would I rewrite this in VB or Python to work in 10? The 'Calculate Geometry' function is useless to me because I want to use it in a model and 'Add X/Y' creates new fields rather than calculating existing ones.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Pre-Logic Script Code:
dim dblx as double
dim dbly as double
dim pPoint as Ipoint
set pPoint = [Shape]
dblx = pPoint.x
dbly = pPoint.y


Field=
dbly
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2011 16:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164917#M12653</guid>
      <dc:creator>GabeMarcello</dc:creator>
      <dc:date>2011-07-05T16:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate X/Y Using VB or Python in a Model</title>
      <link>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164918#M12654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The Add XY coordinates tool pulls the XY coordinates from the shape field. This would be useful for models when you needed to add the fields and also find the X and Y values. It will save a few steps. This tool will also give the Z or M values from the shape field as well if they were enabled on the feature class when it was made. See this link for more information on the tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000032000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000032000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To do a field calculation with the Python parser, see this sample script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def find(shape):
&amp;nbsp; point = shape.getPart(0)
&amp;nbsp; return point.X&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NewX = &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;find(!Shape!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code is a sample modified from the Code samples -geometry section found on this link:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:36:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164918#M12654</guid>
      <dc:creator>StephanieWendel</dc:creator>
      <dc:date>2021-12-11T08:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate X/Y Using VB or Python in a Model</title>
      <link>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164919#M12655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The Add XY coordinates tool pulls the XY coordinates from the shape field. This would be useful for models when you needed to add the fields and also find the X and Y values. It will save a few steps. This tool will also give the Z or M values from the shape field as well if they were enabled on the feature class when it was made. See this link for more information on the tool:&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000032000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000032000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;To do a field calculation with the Python parser, see this sample script.&lt;BR /&gt;Pre-Logic Script Code:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def find(shape):
&amp;nbsp; point = shape.getPart(0)
&amp;nbsp; return point.X&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;NewX = &lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;find(!Shape!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;This code is a sample modified from the Code samples -geometry section found on this link:&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hrm... This works great, but only on blank fields. I tried overwriting and it errors.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-x-y-using-vb-or-python-in-a-model/m-p/164919#M12655</guid>
      <dc:creator>GabeMarcello</dc:creator>
      <dc:date>2021-12-11T08:36:54Z</dc:date>
    </item>
  </channel>
</rss>

