Select to view content in your preferred language

ERROR 002717: Invalid Arcade expression, Arcade error: Identifier expected, Script line: -1548759840

2184
2
Jump to solution
10-16-2022 11:51 PM
GraemeBrowning_Aurizon
Occasional Contributor II

I'm trying to set an Attribute Rule using ArcPy, ArcGIS Pro 3.0.2, a file geodatabase and this code:

 

    arcpy.management.AddAttributeRule(lrsNetworkFC,"Update x_end","CALCULATION",
                                      r"var line_geo =  Dictionary(Text(Geometry($feature)));"\
                                      "var paths = line_geo['paths'];"\
                                      "var vertex_count = 0;"\
                                      "for (var path_idx in paths){;"\
                                      "    for (var vert_idx in paths[path_idx]){;"\
                                      "        vertex_count++;"\
                                      "    };"\
                                      "};"\
                                      "return paths[0][vertex_count - 1][1];",
                                      "EDITABLE", "INSERT;UPDATE", '', '', '', '', "x_end",
                                      "INCLUDE", "NOT_BATCH", None, None)

 

but I'm getting an ERROR 002717:

Traceback (most recent call last):
  File "\\bneprdfps24\gis\GIS\PROJECTS\GRAEME\Scripts\CreateAndLoadLRSDatasetFromCQCN.py", line 391, in <module>
    arcpy.management.AddAttributeRule(lrsNetworkFC,"Update x_end","CALCULATION",
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 1183, in AddAttributeRule
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 1180, in AddAttributeRule
    retval = convertArcObjectToPythonObject(gp.AddAttributeRule_management(*gp_fixargs((in_table, name, type, script_expression, is_editable, triggering_events, error_number, error_message, description, subtype, field, exclude_from_client_evaluation, batch, severity, tags), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 002717: Invalid Arcade expression, Arcade error: Identifier expected, Script line: -1548759840
Failed to execute (AddAttributeRule).

Is there something obvious that is wrong with my syntax? 

I'm trying to use the Attribute Rule to write the X coordinate of the last vertex along a polyline (which is a route in a Roads and Highways LRS Dataset) to a field in its attribute table

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

There are no syntax errors, so this error message is somewhat perplexing.

There are however other problems with your expression:

  • You say you want to return the x coordinate, but you actually return the y coordinate. x is index 0.
  • You calculate the vertex count of the whole multipart geometry and then return that index from the first part. That works for singlepart features, but it will give an error for multipart features, as vertex_count will be greater that the length of the first part.
  • You can do it with a single line:
// no need to convert to Dictionary, you can just call paths
// index -1 gets the last element of an array. paths[-1][-1] gets the last point of the last part.
return Geometry($feature).paths[-1][-1].x

 

Try this expression. If the error still occurs, try setting the rule manually.


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

There are no syntax errors, so this error message is somewhat perplexing.

There are however other problems with your expression:

  • You say you want to return the x coordinate, but you actually return the y coordinate. x is index 0.
  • You calculate the vertex count of the whole multipart geometry and then return that index from the first part. That works for singlepart features, but it will give an error for multipart features, as vertex_count will be greater that the length of the first part.
  • You can do it with a single line:
// no need to convert to Dictionary, you can just call paths
// index -1 gets the last element of an array. paths[-1][-1] gets the last point of the last part.
return Geometry($feature).paths[-1][-1].x

 

Try this expression. If the error still occurs, try setting the rule manually.


Have a great day!
Johannes
GraemeBrowning_Aurizon
Occasional Contributor II

Many thanks @JohannesLindner 

That worked very well and I'm now able to successfully add that attribute rule using this ArcPy code:

arcpy.management.AddAttributeRule(lrsNetworkFC,"Update x_end","CALCULATION",
                                  r"return Geometry($feature).paths[-1][-1].x;",
                                  "EDITABLE", "INSERT;UPDATE", '', '', '', '', "x_end",
                                  "INCLUDE", "NOT_BATCH", None, None)
0 Kudos