<?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 Getting XY map coordinates on mouse clicks as input variables into a python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-xy-map-coordinates-on-mouse-clicks-as/m-p/703964#M54497</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is my first time coding in python, so bear with me. I wrote a script to calculate an analytical solution to find the orientation of a plane based on three points. I'm using ArcGIS 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
from __future__ import division
import arcpy
import numpy as np

# Input points
x1 = float(arcpy.GetParameterAsText(1)) # Point 1
y1 = float(arcpy.GetParameterAsText(2))
z1 = float(arcpy.GetParameterAsText(3))
x2 = float(arcpy.GetParameterAsText(4)) # Point 2
y2 = float(arcpy.GetParameterAsText(5))
z2 = float(arcpy.GetParameterAsText(6))
x3 = float(arcpy.GetParameterAsText(7)) # Point 3
y3 = float(arcpy.GetParameterAsText(8))
z3 = float(arcpy.GetParameterAsText(9))

# Plane equation
A = (y1*z2) + (z1*y3) + (y2*z3) - (z2*y3) - (z3*y1) - (z1*y2)
B = (z2*x3) + (z3*x1) + (z1*x2) - (x1*z2) - (z1*x3) - (x2*z3)
C = (x1*y2) + (y1*x3) + (x2*y3) - (y2*x3) - (y3*x1) - (y1*x2)
D = (z1*y2*x3) + (z2*y3*x1) + (z3*y1*x2) - (x1*y2*z3) - (y1*z2*x3) - (z1*x2*y3)
E = np.sqrt(A**2 + B**2 + C**2)

AZ = np.arctan(A/B) * (180/np.pi) # Preliminary azimuth for dip direction
dip = np.arcsin(-np.cos((np.pi/2) + np.arccos(C/E))) * (180/np.pi) # True dip

# Test for quadrant
alpha = A/E
beta = B/E

# Place dip-direction in proper quadrant
if alpha &amp;gt; 0 and beta &amp;gt; 0:
&amp;nbsp; DD = AZ
elif alpha &amp;gt; 0 and beta &amp;lt; 0:
&amp;nbsp; DD = 180 + AZ
elif alpha &amp;lt; 0 and beta &amp;lt; 0:
&amp;nbsp; DD = 180 + AZ
elif alpha &amp;lt; 0 and beta &amp;gt; 0:
&amp;nbsp; DD = 360 + AZ

# Right-hand rule strike
if DD - 90 &amp;lt; 0:
&amp;nbsp; RHR = 360 + (DD - 90)
else:
&amp;nbsp; RHR = DD - 90

# Centroid coordinates
Cx = (x1+x2+x3)/3
Cy = (y1+y2+y3)/3
Cz = (z1+z2+z3)/3

# Insert centroid point
cursor = arcpy.InsertCursor(arcpy.GetParameterAsText(0)) # Feature class must already exist
row = cursor.newRow()
row.Shape = arcpy.Point(Cx,Cy,Cz)

# Populate table
row.X = Cx
row.Y = Cy
row.Z = Cz
row.DD = DD
row.dip = dip
row.RHR = RHR
cursor.insertRow(row)
del cursor, row

# Refresh MXD
arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works, except that the user has to hover each point and manually enter the coordinates. Ideally, I would like: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(1) the user initially define the target feature layer in a pop-up menu, and hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(2) click on the map to extract the first XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(3) pop-up queries the user for the first Z, hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(4) click on the map to extract the second XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(5) pop-up queries the user for the second Z, hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(6) click on the map to extract the last XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(7) pop-up queries the user for the last Z, hit OK; then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(8) the script runs to completion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the &lt;/SPAN&gt;&lt;A href="http://support.esri.com/en/knowledgebase/techarticles/detail/40730" rel="nofollow noopener noreferrer" target="_blank"&gt;ESRI tool&lt;/A&gt;&lt;SPAN&gt; tutorial that allows the map XY to be displayed on a message box after a mouse-click, but cannot figure out how to pass the variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:36:15 GMT</pubDate>
    <dc:creator>JeffersonChang</dc:creator>
    <dc:date>2021-12-12T05:36:15Z</dc:date>
    <item>
      <title>Getting XY map coordinates on mouse clicks as input variables into a python script</title>
      <link>https://community.esri.com/t5/python-questions/getting-xy-map-coordinates-on-mouse-clicks-as/m-p/703964#M54497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is my first time coding in python, so bear with me. I wrote a script to calculate an analytical solution to find the orientation of a plane based on three points. I'm using ArcGIS 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
from __future__ import division
import arcpy
import numpy as np

# Input points
x1 = float(arcpy.GetParameterAsText(1)) # Point 1
y1 = float(arcpy.GetParameterAsText(2))
z1 = float(arcpy.GetParameterAsText(3))
x2 = float(arcpy.GetParameterAsText(4)) # Point 2
y2 = float(arcpy.GetParameterAsText(5))
z2 = float(arcpy.GetParameterAsText(6))
x3 = float(arcpy.GetParameterAsText(7)) # Point 3
y3 = float(arcpy.GetParameterAsText(8))
z3 = float(arcpy.GetParameterAsText(9))

# Plane equation
A = (y1*z2) + (z1*y3) + (y2*z3) - (z2*y3) - (z3*y1) - (z1*y2)
B = (z2*x3) + (z3*x1) + (z1*x2) - (x1*z2) - (z1*x3) - (x2*z3)
C = (x1*y2) + (y1*x3) + (x2*y3) - (y2*x3) - (y3*x1) - (y1*x2)
D = (z1*y2*x3) + (z2*y3*x1) + (z3*y1*x2) - (x1*y2*z3) - (y1*z2*x3) - (z1*x2*y3)
E = np.sqrt(A**2 + B**2 + C**2)

AZ = np.arctan(A/B) * (180/np.pi) # Preliminary azimuth for dip direction
dip = np.arcsin(-np.cos((np.pi/2) + np.arccos(C/E))) * (180/np.pi) # True dip

# Test for quadrant
alpha = A/E
beta = B/E

# Place dip-direction in proper quadrant
if alpha &amp;gt; 0 and beta &amp;gt; 0:
&amp;nbsp; DD = AZ
elif alpha &amp;gt; 0 and beta &amp;lt; 0:
&amp;nbsp; DD = 180 + AZ
elif alpha &amp;lt; 0 and beta &amp;lt; 0:
&amp;nbsp; DD = 180 + AZ
elif alpha &amp;lt; 0 and beta &amp;gt; 0:
&amp;nbsp; DD = 360 + AZ

# Right-hand rule strike
if DD - 90 &amp;lt; 0:
&amp;nbsp; RHR = 360 + (DD - 90)
else:
&amp;nbsp; RHR = DD - 90

# Centroid coordinates
Cx = (x1+x2+x3)/3
Cy = (y1+y2+y3)/3
Cz = (z1+z2+z3)/3

# Insert centroid point
cursor = arcpy.InsertCursor(arcpy.GetParameterAsText(0)) # Feature class must already exist
row = cursor.newRow()
row.Shape = arcpy.Point(Cx,Cy,Cz)

# Populate table
row.X = Cx
row.Y = Cy
row.Z = Cz
row.DD = DD
row.dip = dip
row.RHR = RHR
cursor.insertRow(row)
del cursor, row

# Refresh MXD
arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works, except that the user has to hover each point and manually enter the coordinates. Ideally, I would like: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(1) the user initially define the target feature layer in a pop-up menu, and hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(2) click on the map to extract the first XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(3) pop-up queries the user for the first Z, hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(4) click on the map to extract the second XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(5) pop-up queries the user for the second Z, hit OK; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(6) click on the map to extract the last XY map coordinates; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(7) pop-up queries the user for the last Z, hit OK; then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(8) the script runs to completion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the &lt;/SPAN&gt;&lt;A href="http://support.esri.com/en/knowledgebase/techarticles/detail/40730" rel="nofollow noopener noreferrer" target="_blank"&gt;ESRI tool&lt;/A&gt;&lt;SPAN&gt; tutorial that allows the map XY to be displayed on a message box after a mouse-click, but cannot figure out how to pass the variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-xy-map-coordinates-on-mouse-clicks-as/m-p/703964#M54497</guid>
      <dc:creator>JeffersonChang</dc:creator>
      <dc:date>2021-12-12T05:36:15Z</dc:date>
    </item>
  </channel>
</rss>

