<?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: ArcPy insert cursor error standalone script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114463#M62914</link>
    <description>&lt;P&gt;I'd suggest catching the exceptions (which also catches arcpy's exceptions) and see if there is anything else causing it to error.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;except Exception as ex:
    print("Error Inserting Rows" + ex))&lt;/LI-CODE&gt;&lt;P&gt;Second thought is do you need to maybe start an edit session?&amp;nbsp; Is the data versioned?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 13:29:08 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-11-05T13:29:08Z</dc:date>
    <item>
      <title>ArcPy insert cursor error standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114460#M62913</link>
      <description>&lt;P&gt;I am trying to convert polygon geometry from one feature class to a 2 point line feature in another feature class.&amp;nbsp; I am reading the data for the polygon(Anno) feature class with a Search Cursor and using an Insert cursor to add the update feature to the line feature class. The logic here basically work within ArcMap and ArcGIS Pro.&amp;nbsp; But I want to run as a standalone script and it errors out when preforming the&amp;nbsp;inscursor.insertRow(nrow).&amp;nbsp; Not really sure what I am missing.&amp;nbsp; The data is stored in an Enterprise database with the connection saved in the script's folder.&amp;nbsp; Any help or suggests would be greatly appreciated.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import datetime&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Local variables:&lt;BR /&gt;web_esmtanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.esmtanno"&lt;BR /&gt;web_lotanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.lotanno"&lt;BR /&gt;web_LotAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.TaxAnnotation\\webrandolph.GISADMIN.LotAnnoLine"&lt;BR /&gt;web_EsmtAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.EsmtAnnoLine"&lt;BR /&gt;DB = "GISadmin to WebRandolph.sde"&lt;BR /&gt;arcpy.env.workspace = DB&lt;/P&gt;&lt;P&gt;def AnnotoLine(AnnoFS, LineFS):&lt;BR /&gt;try:&lt;BR /&gt;msg = arcpy.Describe(LineFS).baseName + " - " + arcpy.Describe(LineFS).dataType&lt;BR /&gt;print(msg)&lt;BR /&gt;msg = arcpy.Describe(AnnoFS).baseName + " - " + arcpy.Describe(AnnoFS).dataType&lt;BR /&gt;print (msg)&lt;BR /&gt;print (arcpy.Describe(AnnoFS).catalogPath)&lt;BR /&gt;inscursor = arcpy.da.InsertCursor(LineFS,['SHAPE@','TEXTSTRING','PID'])&lt;BR /&gt;cursor = arcpy.da.SearchCursor(AnnoFS,['OID@','SHAPE@','TextString'])&lt;BR /&gt;for row in cursor:&lt;BR /&gt;#print("In row cursor")&lt;BR /&gt;pntcnt = 0&lt;BR /&gt;ID = row[0]&lt;BR /&gt;poly = row[1]&lt;BR /&gt;txt = row[2].strip()&lt;BR /&gt;if poly.type == 'polygon':&lt;BR /&gt;poly1 = poly.getPart(0)&lt;BR /&gt;for pnt in poly1:&lt;BR /&gt;# print("Point: " + str(pntcnt))&lt;BR /&gt;if pntcnt == 0:&lt;BR /&gt;spoint = pnt&lt;BR /&gt;pntcnt += 1&lt;BR /&gt;# print(str(ID) + "(" + str(pntcnt) + ")-" + str(spoint.X) + "," + str(spoint.Y))&lt;BR /&gt;else:&lt;BR /&gt;if pntcnt &amp;lt; 4:&lt;BR /&gt;epoint = pnt&lt;BR /&gt;pntcnt += 1&lt;BR /&gt;# print (str(ID) + "(" + str(pntcnt) + ")-" + str(epoint.X) + "," + str(epoint.Y))&lt;BR /&gt;spref = poly.spatialReference&lt;BR /&gt;parray = arcpy.Array([spoint,epoint])&lt;BR /&gt;pline = arcpy.Polyline(parray,spref)&lt;BR /&gt;nrow = ([pline,text,ID])&lt;BR /&gt;inscursor.insertRow(nrow)&lt;BR /&gt;print (ID + ": was processed.")&lt;BR /&gt;else:&lt;BR /&gt;print (ID + ": shape invalid.")&lt;BR /&gt;except:&lt;BR /&gt;print("Error Inserting Rows" + arcpy.GetMessages(2))&lt;BR /&gt;finally:&lt;BR /&gt;del nrow, inscursor&lt;BR /&gt;del row, cursor&lt;BR /&gt;&lt;BR /&gt;print ("Start time: " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M%p"))&lt;/P&gt;&lt;P&gt;### Process: Update Parcel Annotation&lt;BR /&gt;try:&lt;BR /&gt;arcpy.DeleteFeatures_management(web_EsmtAnnoLine)&lt;BR /&gt;print "Cleared EsmtAnnoLine"&lt;BR /&gt;AnnotoLine(web_esmtanno,web_EsmtAnnoLine)&lt;BR /&gt;except:&lt;BR /&gt;##print "!! Could not update Annotation!!!"&lt;BR /&gt;msg = "Error updating Parcel Annotation!!!" + '\n'&lt;BR /&gt;msg += arcpy.GetMessages(2) + '\n'&lt;BR /&gt;print(msg)&lt;BR /&gt;##email_msg.sendmsg(msg,"Error UpdateWebAnno.py")&lt;/P&gt;&lt;P&gt;print "Finish time: " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M%p")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 13:17:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114460#M62913</guid>
      <dc:creator>Smith_Linda</dc:creator>
      <dc:date>2021-11-05T13:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy insert cursor error standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114463#M62914</link>
      <description>&lt;P&gt;I'd suggest catching the exceptions (which also catches arcpy's exceptions) and see if there is anything else causing it to error.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;except Exception as ex:
    print("Error Inserting Rows" + ex))&lt;/LI-CODE&gt;&lt;P&gt;Second thought is do you need to maybe start an edit session?&amp;nbsp; Is the data versioned?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 13:29:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114463#M62914</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-11-05T13:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy insert cursor error standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114483#M62915</link>
      <description>&lt;P&gt;I finally got this to work.&amp;nbsp; A couple of typos and I moved the data out of a Geodataset which I think had locks.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import datetime&lt;BR /&gt;#import email_msg&lt;/P&gt;&lt;P&gt;# Local variables:&lt;BR /&gt;web_esmtanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.esmtanno"&lt;BR /&gt;web_lotanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.lotanno"&lt;BR /&gt;web_LotAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.TaxAnnotation\\webrandolph.GISADMIN.LotAnnoLine"&lt;BR /&gt;web_EsmtAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.EsmtAnnoLine"&lt;BR /&gt;DB = "GISadmin to WebRandolph.sde"&lt;BR /&gt;arcpy.env.workspace = DB&lt;/P&gt;&lt;P&gt;def AnnotoLine(AnnoFS, LineFS):&lt;BR /&gt;try:&lt;BR /&gt;msg = arcpy.Describe(LineFS).baseName + " - " + arcpy.Describe(LineFS).dataType&lt;BR /&gt;print(msg)&lt;BR /&gt;msg = arcpy.Describe(AnnoFS).baseName + " - " + arcpy.Describe(AnnoFS).dataType&lt;BR /&gt;print (msg)&lt;BR /&gt;print (arcpy.Describe(AnnoFS).catalogPath)&lt;BR /&gt;inscursor = arcpy.da.InsertCursor(LineFS,['SHAPE@','TEXTSTRING','PID'])&lt;BR /&gt;cursor = arcpy.da.SearchCursor(AnnoFS,['OID@','SHAPE@','TextString'])&lt;BR /&gt;for row in cursor:&lt;BR /&gt;print("In row cursor")&lt;BR /&gt;pntcnt = 0&lt;BR /&gt;ID = row[0]&lt;BR /&gt;poly = row[1]&lt;BR /&gt;txt = row[2].strip()&lt;BR /&gt;if poly.type == 'polygon':&lt;BR /&gt;poly1 = poly.getPart(0)&lt;BR /&gt;for pnt in poly1:&lt;BR /&gt;# print("Point: " + str(pntcnt))&lt;BR /&gt;if pntcnt == 0:&lt;BR /&gt;spoint = pnt&lt;BR /&gt;pntcnt += 1&lt;BR /&gt;# print(str(ID) + "(" + str(pntcnt) + ")-" + str(spoint.X) + "," + str(spoint.Y))&lt;BR /&gt;else:&lt;BR /&gt;if pntcnt &amp;lt; 4:&lt;BR /&gt;epoint = pnt&lt;BR /&gt;pntcnt += 1&lt;BR /&gt;# print (str(ID) + "(" + str(pntcnt) + ")-" + str(epoint.X) + "," + str(epoint.Y))&lt;BR /&gt;spref = poly.spatialReference&lt;BR /&gt;parray = arcpy.Array([spoint,epoint])&lt;BR /&gt;pline = arcpy.Polyline(parray,spref)&lt;BR /&gt;print("Polyline set")&lt;BR /&gt;nrow = ([pline,txt,ID])&lt;BR /&gt;inscursor.insertRow(nrow)&lt;BR /&gt;print (str(ID) + ": was processed.")&lt;BR /&gt;else:&lt;BR /&gt;print (str(ID) + ": shape invalid.")&lt;BR /&gt;except arcpy.ExecuteError:&lt;BR /&gt;print(arcpy.GetMessages())&lt;BR /&gt;finally:&lt;BR /&gt;del inscursor&lt;BR /&gt;del row, cursor&lt;BR /&gt;&lt;BR /&gt;print ("Start time: " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M%p"))&lt;/P&gt;&lt;P&gt;### Process: Update Parcel Annotation&lt;BR /&gt;try:&lt;BR /&gt;arcpy.DeleteFeatures_management(web_EsmtAnnoLine)&lt;BR /&gt;print "Cleared EsmtAnnoLine"&lt;BR /&gt;AnnotoLine(web_esmtanno,web_EsmtAnnoLine)&lt;BR /&gt;except arcpy.ExecuteError:&lt;BR /&gt;##print "!! Could not update Annotation!!!"&lt;BR /&gt;msg = "Error updating Parcel Annotation!!!" + '\n'&lt;BR /&gt;msg += arcpy.GetMessages()&lt;BR /&gt;print(msg)&lt;BR /&gt;##email_msg.sendmsg(msg,"Error UpdateWebAnno.py")&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 14:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114483#M62915</guid>
      <dc:creator>Smith_Linda</dc:creator>
      <dc:date>2021-11-05T14:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy insert cursor error standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114487#M62916</link>
      <description>&lt;P&gt;Seeing the ArcPy errors helped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 14:35:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114487#M62916</guid>
      <dc:creator>Smith_Linda</dc:creator>
      <dc:date>2021-11-05T14:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy insert cursor error standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114517#M62917</link>
      <description>&lt;P&gt;Depending on your needs, you might want to wrap your geoprocessing functions within a Try/Except block.&amp;nbsp; We have several scripts that we run in off hours so if something goes south, we like to get an email telling us so.&amp;nbsp; The except block invokes the sendEmail() def.&amp;nbsp; We also like to log all the processes so we can see what worked and what didn't:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def createAliasTable(msdCenterlines,centerlinesAlias,logoutput):
    
    defName = 'Create Alias Table'
    try:
        select = "NAME &amp;gt;= 'A'"
        arcpy.management.MakeFeatureLayer(msdCenterlines, 'centerlinesLyr', select)

        arcpy.TruncateTable_management(centerlinesAlias)
        
        arcpy.management.Append('centerlinesLyr',centerlinesAlias,'NO_TEST')
        
        createTime = time.strftime('%Y-%m-%d %H:%M:%S')
        logoutput.write(f'Success: completed {defName} at {createTime}\n')

    except Exception as err:
        failTime = time.strftime('%Y-%m-%d %H:%M:%S')
        logoutput.write(f'Failure: Unable to complete {defName} at {failTime}\n ')
        logoutput.write(f'{err}\n')
        sendEmail(err)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the try/except approach, if the script tosses an error somewhere along the line, it won't totally blow up and shut down. We standardize all of our scripts with geoprocessing defs and call them from the main def, passing variables as arguments/parameters set there.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main():
    logFile = r"N:\GIS\Scripts\Logs\CreateCityWorksLocator.txt"   
    if os.path.exists(logFile):
        os.remove(logFile)
    logoutput = open(logFile,'a')
    
    startUp(logoutput)

    #set input parameters for various defs()
    ws = r'N:\GIS\Geocoding\CityWorksLocators\GeocodingData.gdb'
    sde = r'\\path\to\connectionFile\SLCOmsd@MSD.sde'
    municipalities = f'{sde}\MSD.SLCOMSD.MunicipalitiesMSD'
    centerlinesAlias = f'{ws}\CenterlinesMSD_Alias'
    locatorDir = r'N:\GIS\Geocoding\CityWorksLocators\Locators\Joes'
    parcels = r'J:\ConnectionFile\aDifferent.sde\MSD.SLCOMSD.SLCo_Parcels'
    slcoCenterlines = f'{sde}\MSD.SLCOMSD.SLCo_Centerlines'
    slcoAddressPoints = f'{sde}\MSD.SLCOMSD.SLCo_AddressPoints'
    msdCenterlines = f'{sde}\MSD.SLCOMSD.CenterlinesMSD'
    msdAddressPoints = f'{sde}\MSD.SLCOMSD.SiteAddressPointsMSD'
    msdFgbAddressPoints = f'{ws}\SiteAddressPointsMSD'
        
    #call the defs  comment out as needed for testing purposes 
    
    #arcelsToFGDB(parcels,ws,municipalities,logoutput)
    #createParcelLocator(parcels,locatorDir,logoutput)
    #createNonMsdParcelLocator(ws,locatorDir,logoutput)
    #createAliasTable(msdCenterlines,centerlinesAlias,logoutput)
    #nonMsdAddressPoints(ws,slcoAddressPoints,municipalities,logoutput)
    #nonMsdCenterlines(ws,slcoCenterlines,municipalities,logoutput)
    #nonMsdLocator(ws,locatorDir,logoutput)
    #createMsdAddressPoints(ws,msdAddressPoints,logoutput)
    #msdLocator(ws,centerlinesAlias,msdFgbAddressPoints,msdCenterlines,locatorDir,logoutput)
    compositeLocator(locatorDir,logoutput)

if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;Notice that all the calls to the various defs are commented out; with a modular approach, you can only run the defs you want to.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:44:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-insert-cursor-error-standalone-script/m-p/1114517#M62917</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-05T15:44:02Z</dc:date>
    </item>
  </channel>
</rss>

