<?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: Migrate tool/script from ArcMap to ArcGIS Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1404461#M70238</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;,&amp;nbsp;yes, I can execute the tool multiple times.&amp;nbsp; Try adding&amp;nbsp;&lt;STRONG&gt;del cursor&lt;/STRONG&gt; below the SearchCursor:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1712053105334.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99724i7EBE5FB148811F9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1712053105334.png" alt="JakeSkinner_0-1712053105334.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2024 10:18:34 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-04-02T10:18:34Z</dc:date>
    <item>
      <title>Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394258#M70032</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have a tool/script that performed exceptionally well in ArcMap both as a tool/script and as an Add-in. However, I've been attempting to convert it to ArcGIS Pro without success. This tool/script in ArcMap allowed users to calculate the distance between two points with just two clicks, essentially creating a polyline that conveyed the length for further calculations. It also generated a point and updated a field based on this calculation. Although I've attempted to replicate the parameters from ArcMap in Pro, the tool fails to function as expected. It doesn't allow me to click on the map or initiate any actions. How can I go about ensuring this script works in ArcGIS Pro?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;The noticeable difference that I see in the parameters section is that script in pro doesn't have Schema.&lt;/P&gt;&lt;P&gt;ArcMap parameters:&lt;/P&gt;&lt;P&gt;Input - Feature Set-&lt;/P&gt;&lt;P&gt;Type - Required&lt;/P&gt;&lt;P&gt;Direction - Input&lt;/P&gt;&lt;P&gt;MultiValue - no&lt;/P&gt;&lt;P&gt;Schema - points to the Point layer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import env
import pythonaddins
import os

fc = "Points"
arcpy.env.workspace = r"C:\Temp\PointsTest.mdb"
pointLayer = arcpy.env.workspace + os.sep + "Points" #target point feature class 

if arcpy.Exists ("line_test"): 
    arcpy.Delete_management ("line_test")

# Start an edit session. Must provide the worksapce.
edit = arcpy.da.Editor(arcpy.env.workspace)

# Edit session is started without an undo/redo stack for versioned data
#  (for second argument, use False for unversioned data)
edit.startEditing(True)

# Start an edit operation
edit.startOperation()

input = arcpy.GetParameterAsText(0)
Range = float(arcpy.GetParameterAsText(1))
# Create empty Point and Array objects
point = arcpy.Point()
array = arcpy.Array()

# A list that will hold each the Polyline object
featureList = []

rows = arcpy.SearchCursor(input)
for row in rows:
    geom = row.Shape
    point.X = geom.centroid.X
    point.Y = geom.centroid.Y
    # Add each point to the array
    array.add(point)    

# Create the polyline
polyline = arcpy.Polyline(array)
# Clear the array for future use
array.removeAll()
featureList.append(polyline)

del row, rows

# Copy the polyline to file geodatabase to create a Shape_Length field
arcpy.CopyFeatures_management(featureList, "line_test")
with arcpy.da.SearchCursor("line_test", ["SHAPE@","SHAPE@LENGTH"]) as cursor:
    for row in cursor:
        X = row[0].lastPoint.X
        Y = row[0].lastPoint.Y
        length = row[1] / 5.28
        print("Length:", length)

row_value = (length, (X, Y))
        
cursor = arcpy.da.InsertCursor(pointLayer, ("SiteNum", "SHAPE@XY"))
cursor.insertRow(row_value)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-in,&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pythonaddins

class PointTool(object):
    """Implementation for Point_addin.PointTool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor=3
        self.shape = "Line" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
        def onLine(self, line_geometry):
            
        fc = "Points"
        arcpy.env.workspace = r"C:\Temp\PointsTest.mdb"
        pointLayer = arcpy.env.workspace + os.sep + "Points" #target point feature class 

        if arcpy.Exists ("line_test"): 
            arcpy.Delete_management ("line_test")

        # Start an edit session. Must provide the worksapce.
        edit = arcpy.da.Editor(arcpy.env.workspace)

        # Edit session is started without an undo/redo stack for versioned data
        #  (for second argument, use False for unversioned data)
        edit.startEditing(True)

        # Start an edit operation
        edit.startOperation()

        input = arcpy.GetParameterAsText(0)
        Range = float(arcpy.GetParameterAsText(1))
        # Create empty Point and Array objects
        point = arcpy.Point()
        array = arcpy.Array()

        # A list that will hold each the Polyline object
        featureList = []

        rows = arcpy.SearchCursor(input)
        for row in rows:
            geom = row.Shape
            point.X = geom.centroid.X
            point.Y = geom.centroid.Y
            # Add each point to the array
            array.add(point)    

        # Create the polyline
        polyline = arcpy.Polyline(array)
        # Clear the array for future use
        array.removeAll()
        featureList.append(polyline)

        del row, rows

        # Copy the polyline to file geodatabase to create a Shape_Length field
        arcpy.CopyFeatures_management(featureList, "line_test")
        with arcpy.da.SearchCursor("line_test", ["SHAPE@","SHAPE@LENGTH"]) as cursor:
            for row in cursor:
                X = row[0].lastPoint.X
                Y = row[0].lastPoint.Y
                length = row[1] / 5.28
                print("Length:", length)

        row_value = (length, (X, Y))
                
        cursor = arcpy.da.InsertCursor(pointLayer, ("SiteNum", "SHAPE@XY"))
        cursor.insertRow(row_value)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 18:03:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394258#M70032</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-11T18:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394403#M70033</link>
      <description>&lt;P&gt;Full disclosure, I'm not sure any of the below points are the issue, except maybe #2 (Line 49).&amp;nbsp; That said, a&amp;nbsp;few things that jump out at me in no particular order:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Script, Line 32&lt;/STRONG&gt;&lt;OL&gt;&lt;LI&gt;It's generally best practice to use the cursors via a&amp;nbsp;&lt;STRONG&gt;with&lt;/STRONG&gt; statement to ensure they get closed properly.&lt;/LI&gt;&lt;LI&gt;The DA cursors are generally more efficient than the standard cursors.&amp;nbsp; Why use a standard one here?&lt;/LI&gt;&lt;LI&gt;Compare this to line 50, where you avoid both of these issues.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Script, Line 49&lt;/STRONG&gt;&lt;OL&gt;&lt;LI&gt;I could be dead-wrong here, but are you sure you want&amp;nbsp;&lt;STRONG&gt;CopyFeatures&lt;/STRONG&gt;?&amp;nbsp; Shouldn't it be&amp;nbsp;&lt;STRONG&gt;CreateFeatureclass&lt;/STRONG&gt;?&lt;/LI&gt;&lt;LI&gt;Reviewing the specs for&amp;nbsp;&lt;STRONG&gt;CopyFeatures&lt;/STRONG&gt;, it looks like it requires a Feature Class as input.&amp;nbsp; I admit I haven't used it much from Python; can it take a list of Polylines?&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Script, Line 50&lt;/STRONG&gt;&lt;OL&gt;&lt;LI&gt;Why call&amp;nbsp;&lt;U&gt;both&lt;/U&gt;&amp;nbsp;&lt;STRONG&gt;SHAPE@&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;SHAPE@LENGTH&lt;/STRONG&gt;?&amp;nbsp; You can just call one of them.&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;length&lt;/STRONG&gt; is an attribute of that geometry object, just like&amp;nbsp;&lt;STRONG&gt;lastPoint&lt;/STRONG&gt; is; see line 5, below:&lt;/LI&gt;&lt;LI&gt;Not important, but Python 3 has added a new way of inserting variables into strings that can be a bit more user-friendly and with better control.&amp;nbsp; Personally, I've found it generally more pleasant to use than the older&amp;nbsp;&lt;STRONG&gt;string.format()&lt;/STRONG&gt;, &lt;STRONG&gt;%s&lt;/STRONG&gt;, and print command concatenation methods.&amp;nbsp; See line 6, below:&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor('line_test', 'SHAPE@') as cursor:
  for row in cursor:
    x = row[0].lastPoint.X
    y = row[0].lastPoint.Y
    length = row[0].length / 5.28
    print(f'Length: {length}')​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Script, Line 59&lt;/STRONG&gt;&lt;OL&gt;&lt;LI&gt;See my comments about&amp;nbsp;&lt;STRONG&gt;Line 32&lt;/STRONG&gt;, above.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Add-in, Lines 11-66&lt;/STRONG&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;I'm assuming this is a copy-paste issue, but you seem to have an indentation error.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 11 Mar 2024 22:12:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394403#M70033</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-03-11T22:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394572#M70034</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You could use something like below to create the line feature class:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import arcpy

# Variables
input = arcpy.GetParameterAsText(0)
gdb = r"C:\temp\python\test.gdb"
wkid = 2272

# Environment Variables
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(2272)

arcpy.env.workspace = gdb

array = arcpy.Array()

with arcpy.da.SearchCursor(input, ["SHAPE@X", "SHAPE@Y"]) as cursor:
  for row in cursor:
    pt = arcpy.Point(row[0], row[1])
    array.add(pt)
del cursor

polyline = arcpy.Polyline(array)

arcpy.CopyFeatures_management(polyline, "line_test")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 12 Mar 2024 10:43:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394572#M70034</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-12T10:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394702#M70035</link>
      <description>&lt;P&gt;My bad, I had different variations going on.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 15:36:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394702#M70035</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-12T15:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394722#M70036</link>
      <description>&lt;P&gt;Is there a tool in Pro that I need to use to initiate me to allow me to click on the map?&amp;nbsp; It currently doesn't allow me to do that with the following parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently using legacy toolbox script.&lt;/P&gt;&lt;P&gt;I have set up the parameters, like so.&lt;/P&gt;&lt;P&gt;Input:&lt;/P&gt;&lt;P&gt;Label - Input&lt;/P&gt;&lt;P&gt;Name - Input&lt;/P&gt;&lt;P&gt;Data type - Feature Set&lt;/P&gt;&lt;P&gt;Type - Required&lt;/P&gt;&lt;P&gt;Direction - Input&lt;/P&gt;&lt;P&gt;Default - points to .lyr file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rang:&lt;/P&gt;&lt;P&gt;Label - Input&lt;/P&gt;&lt;P&gt;Name - Input&lt;/P&gt;&lt;P&gt;Data Type - Double&lt;/P&gt;&lt;P&gt;Type - Required&lt;/P&gt;&lt;P&gt;Direction - Input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current code,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Set up your environment
fc = "Points"
arcpy.env.workspace = r"C:\Temp\PointsTest.gdb"
pointLayer = os.path.join(arcpy.env.workspace, "Points")  # target point feature class

# Check if "line_test" exists and delete it if it does
if arcpy.Exists("line_test"): 
    arcpy.Delete_management("line_test")

# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(arcpy.env.workspace)

# Edit session is started without an undo/redo stack for versioned data
# (for the second argument, use False for unversioned data)
edit.startEditing(True)

# Variables
input = arcpy.GetParameterAsText(0)
gdb = r"C:\Temp\PointsTest.gdb"
wkid = 2272

# Set environment variables
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(2272)
arcpy.env.workspace = gdb

array = arcpy.Array()

# Iterate over the features in the input and create a polyline
with arcpy.da.SearchCursor(input, ["SHAPE@X", "SHAPE@Y"]) as cursor:
    for row in cursor:
        pt = arcpy.Point(row[0], row[1])
        array.add(pt)

# Create a polyline from the array
polyline = arcpy.Polyline(array)

# Save the polyline to "line_test" feature class
arcpy.CopyFeatures_management(polyline, "line_test")

# Retrieve the last point of the polyline and calculate its attributes
with arcpy.da.SearchCursor("line_test", "SHAPE@") as cursor:
    for row in cursor:
        X = row[0].lastPoint.X
        Y = row[0].lastPoint.Y
        length = row[0].length / 5.28
        print("Length:", length)

# Prepare the row value tuple
row_value = (length, (X, Y))

# Use arcpy.da.InsertCursor with a context manager to insert rows into the point layer
with arcpy.da.InsertCursor(fc, ["SiteNum", "SHAPE@XY"]) as cursor:
    cursor.insertRow(row_value)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 15:57:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394722#M70036</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-12T15:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394730#M70037</link>
      <description>&lt;P&gt;Click pencil next to the folder to select the geometry type, and then you should be able to create features&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 16:02:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394730#M70037</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-12T16:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394778#M70038</link>
      <description>&lt;P&gt;In the input parameters&amp;nbsp; dependency I had it pointing to a .lyr file and gave me totally something different. After removing that .lyr and starting a edit session I am able to see what you see. After clicking on points, it appears that a point layer is created based on the name of the script, for mine it was PointTestScript input(Points), temp layer?, I get options to use point or point at the end of line, I've tried both. The point doesn't do anything other then just create points in the temp layer? If I use the point at the end of line I get error, line 45, in &amp;lt;module&amp;gt;&lt;BR /&gt;X = row[0].lastPoint.X&lt;BR /&gt;AttributeError: 'NoneType' object has no attribute 'lastPoint'&lt;/P&gt;&lt;P&gt;Inside the database there is layers being created that correspond with the temp point layers, "Points_1", "Points_2", etc. with field names Name, Text, IntegerValue, DoubleValue and DateTime, but they are empty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I appreciate your help and patience.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 17:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1394778#M70038</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-12T17:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395198#M70043</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Can you &lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_self"&gt;post&lt;/A&gt; the updated code your using?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 12:45:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395198#M70043</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-13T12:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395277#M70045</link>
      <description>&lt;P&gt;Of course.&lt;/P&gt;&lt;P&gt;From what I can tell, the "polyline" doesn't get created inside the database, which is why I am getting the error. I just see "points" with the fields I mention before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Set the workspace and target point feature class
workspace = r"C:\Temp\PointsTest.gdb"
arcpy.env.workspace = workspace
fc = "Points"
pointLayer = os.path.join(workspace, "CCAP")  # Corrected quotation marks here

# Variables
input = arcpy.GetParameterAsText(0)  # Changed variable name to follow Python conventions
Range = float(arcpy.GetParameterAsText(1))
wkid = 26770  # Corrected wkid to match the spatial reference

# Environment Variables
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(wkid)  # Corrected the spatial reference wkid

# Delete line_test if exists
if arcpy.Exists("line_test"):
    arcpy.Delete_management("line_test")

# Create an array to hold the point geometries
array = arcpy.Array()

# Iterate through the input features to create the polyline
with arcpy.da.SearchCursor(input, ["SHAPE@X", "SHAPE@Y"]) as cursor:
    for row in cursor:
        pt = arcpy.Point(row[0], row[1])
        array.add(pt)
del cursor

# Create the polyline from the array of points
polyline = arcpy.Polyline(array)

# Save the polyline to a file
arcpy.CopyFeatures_management(polyline, "line_test")

# Retrieve the last point's coordinates and calculate length
with arcpy.da.SearchCursor("line_test", "SHAPE@") as cursor:
    for row in cursor:
        last_point = row[0].lastPoint
        X = last_point.X
        Y = last_point.Y
        length = row[0].length / 5.28
        print("Length:", length)

# Prepare values to insert into the point layer
row_value = (length, (X, Y))

# Use arcpy.da.InsertCursor with a context manager to insert rows into the point layer
with arcpy.da.InsertCursor(pointLayer, ["SiteNum", "SHAPE@XY"]) as cursor:
    cursor.insertRow(row_value)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 15:27:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395277#M70045</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-13T15:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395304#M70046</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Make sure your map is in coordinate system (26770), then try the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import arcpy

# Variables
input = arcpy.GetParameterAsText(0)
gdb = r"C:\temp\PointsTest.gdb"
wkid = 26770

# Environment Variables
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(wkid)

arcpy.env.workspace = gdb  

array = arcpy.Array()

with arcpy.da.SearchCursor(input, ["SHAPE@X", "SHAPE@Y"]) as cursor:
  for row in cursor:
    pt = arcpy.Point(row[0], row[1])
    array.add(pt)
del cursor

polyline = arcpy.Polyline(array)

arcpy.AddMessage("Copying line features")
arcpy.CopyFeatures_management(polyline, "line_test")

# Retrieve the last point's coordinates and calculate length
with arcpy.da.SearchCursor("line_test", "SHAPE@") as cursor:
    for row in cursor:
        last_point = row[0].lastPoint
        X = last_point.X
        Y = last_point.Y
        length = row[0].length / 5.28
        arcpy.AddMessage(f"Length:  {length}")

# Prepare values to insert into the point layer
row_value = (length, (X, Y))

# Use arcpy.da.InsertCursor with a context manager to insert rows into the point layer
arcpy.AddMessage("Inserting values into point layer")
with arcpy.da.InsertCursor("CCAP", ["SiteNum", "SHAPE@XY"]) as cursor:
    cursor.insertRow(row_value)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 15:36:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1395304#M70046</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-13T15:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1396001#M70055</link>
      <description>&lt;P&gt;I did have to add, Range = float(arcpy.GetParameterAsText(1)) and&amp;nbsp; included it in, length = row[0].length / 5.28 + Range.&lt;/P&gt;&lt;P&gt;I am not getting a different error, a lock error.&lt;/P&gt;&lt;P&gt;line 48, in &amp;lt;module&amp;gt;&lt;BR /&gt;cursor.insertRow(row_value)&lt;BR /&gt;RuntimeError: Cannot acquire a lock.&lt;/P&gt;&lt;P&gt;I am using "Point at end of Line" from the drop down and with"Points" in the input drop down window.&lt;/P&gt;&lt;P&gt;I click on the drawing tool to the right, then click points, and click on "selecting point at end of line", it automatically populates with "Scrip Input(points)" in the TOC, I change it to "Points". Is this correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 15:49:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1396001#M70055</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-14T15:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1396229#M70057</link>
      <description>&lt;P&gt;Try the attached tool.&amp;nbsp; First, update the &lt;STRONG&gt;gdb&amp;nbsp;&lt;/STRONG&gt;variable by right-clicking on the toolbox &amp;gt; Properties &amp;gt; Execution:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1710442949693.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/98079iAA7929263CB39C47/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1710442949693.png" alt="JakeSkinner_0-1710442949693.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next, double-click the&amp;nbsp;&lt;STRONG&gt;Script&lt;/STRONG&gt; tool.&amp;nbsp; Click the dropdown next the pencil and select&amp;nbsp;&lt;STRONG&gt;Points.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;Create two points and execute the tool.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 19:03:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1396229#M70057</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-14T19:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1397257#M70078</link>
      <description>&lt;P&gt;I am still getting the error, Cannot acquire a lock.&lt;/P&gt;&lt;P&gt;I have attached an image.&lt;/P&gt;&lt;P&gt;Would you like me to upload some test data samples?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 14:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1397257#M70078</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-18T14:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1397739#M70084</link>
      <description>&lt;P&gt;Remove the CCAP feature class from your map and try executing the tool again.&amp;nbsp; I think this is placing a lock on the feature class, which is causing this error.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 10:47:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1397739#M70084</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-19T10:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1399285#M70123</link>
      <description>&lt;P&gt;Removing the layer would not ideal because I need that layer on the map.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:39:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1399285#M70123</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-21T20:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1399566#M70129</link>
      <description>&lt;P&gt;I can't reproduce this.&amp;nbsp; I'm working with Pro 3.2.2 and a File Geodatabase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6349460434112w996h540r788" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6349460434112" data-account="6161463677001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6349460434112w996h540r788');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.esri.com/t5/video/gallerypage/video-id/6349460434112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 10:05:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1399566#M70129</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-22T10:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1400910#M70170</link>
      <description>&lt;P&gt;I will try it on a new project and report back.&lt;/P&gt;&lt;P&gt;Again, thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 14:35:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1400910#M70170</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-03-26T14:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1404071#M70232</link>
      <description>&lt;P&gt;Sorry for the delay. I did test it and it does work but for only the first time. If I need to run the script tool again I get the error - line 35, in &amp;lt;module&amp;gt;&lt;BR /&gt;RuntimeError: Cannot acquire a lock.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you able to run the script tool multiple times?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 21:23:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1404071#M70232</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-04-01T21:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1404461#M70238</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;,&amp;nbsp;yes, I can execute the tool multiple times.&amp;nbsp; Try adding&amp;nbsp;&lt;STRONG&gt;del cursor&lt;/STRONG&gt; below the SearchCursor:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1712053105334.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99724i7EBE5FB148811F9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1712053105334.png" alt="JakeSkinner_0-1712053105334.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 10:18:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1404461#M70238</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-04-02T10:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate tool/script from ArcMap to ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1405919#M70259</link>
      <description>&lt;P&gt;It's working now, thank you for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 17:46:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migrate-tool-script-from-arcmap-to-arcgis-pro/m-p/1405919#M70259</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-04-04T17:46:57Z</dc:date>
    </item>
  </channel>
</rss>

