Select to view content in your preferred language

Network Analyst and Script Evaluators: accessing attributes, get "network element evaluator error"

4493
26
05-06-2018 12:00 PM
BradSrebnik
Occasional Contributor

I'm trying to create a route using Network Analyst.  Just at the beginning stages of setting this up for a school project.

I have a feature class called RoadsClipped, and successfully set up a Network Dataset called Roads_ND using it.

Now I'm trying to customize the routing cost using evaluators.  I want to use attributes in RoadsClipped, but anything I've tried to access those attributes results in a "Network element evaluator error".  I've tried both VBScript and Python.

Some simple examples are below.  I've tried literally hundreds of variations and nothing work unless I forego trying to look at the attribute entirely.  These are just simple tests to see if I can get at the attributes in RoadsClipped, and not the real logic I'll eventually use.

Python:

def SetCost(value):
    a=Edge.AttributeValueByName(value)
    c=0
    if l!=0:
        c=100/a
    return c

value=SetCost("SPEED_LIM")

VBScript:

a=0
a=Edge.AttributeValueByName("SPEED_LIM")

value = a

Any suggestions?

0 Kudos
26 Replies
BradSrebnik
Occasional Contributor

More information.  I'm using ArcMap Desktop 10.5.1 on Windows 7.  RoadsClipped has about 2000 records.

DanPatterson_Retired
MVP Emeritus

The variables in your 'def' aren't defined anywhere, so your logic can't be tested.

0 Kudos
BradSrebnik
Occasional Contributor

Thanks for the reply...  All the examples in ESRI help that I could find (two for each of VBScript and Python) do not define the variables.  How do you do that?  I just tried adding a "Dim l" line to the VBScript and still got the same error.  I don't think you need to define variables for Python, right?

0 Kudos
BradSrebnik
Occasional Contributor

Note ....  This isn't freestanding script code.  It's entered in Network Dataset Properties, Attributes tab, click on Evaluators, set to Script, click on Evaluator Properties.  The main part of the code is the "Pre-Logic Script Code", and the last line that sets the value is the actual call.  I followed (roughly) examples from Types of evaluators used by a network—Help | ArcGIS Desktop and Assigning evaluators—Help | ArcGIS Desktop  .

0 Kudos
MelindaMorang
Esri Regular Contributor

Are you just trying to read a value from the RoadsClipped attribute table and use that to derive the cost?  If so, you don't need a Script evaluator.  You can use a Field evaluator.  Like with script, click on Evaluator Properties to open up the dialog where you can set up some pre-logic script code.

This was your python example from before:

def SetCost(value):
    a=Edge.AttributeValueByName(value)
    c=0
    if l!=0:
        c=100/a
    return c
 
value=SetCost("SPEED_LIM")

Note that for a field evaluator, you do not need Edge.AttributeValueByName(value).  In this case, "value" will be the field value read from the RoadsClipped attribute table.

So, let's just say the speed limit is 30, as an example.  You don't need the "a" variable at all.  You can just use "value".

def SetCost(value):
    c=0
    if l!=0:
        c=100/value
    return c
 
value=SetCost("SPEED_LIM")

What is "l"?  I think this is where your problem lies.  As Dan says above, this variable isn't defined.

0 Kudos
BradSrebnik
Occasional Contributor

Thanks for the reply, but it did not work.  That is a lower-case L variable.  Defining it is NOT necessary in Python.  I can verify that.  If I do this:

def SetCost(value):
    c=0
    if value!=0:
        c=100/value
    return c

Value = SetCost(0)

it runs without error, but does not access SPEED_LIM as I need it to.

If I ONLY change the call to

Value = SetCost("SPEED_LIM")

I get the same error as noted in my original post.

0 Kudos
MelindaMorang
Esri Regular Contributor

What's in your SPEED_LIM field in your data?  Maybe it has null values that need to be handled separately.  If there were a null value, then the script would fail (because 100/null is undefined) and would return an error.

0 Kudos
BradSrebnik
Occasional Contributor

It is an integer.  One record has a null value.  That's why I check if value is 0.  In any case, that is not the problem.  I just change it to another attribute that is also an integer and has no null values.  I get the same error.

I'm hoping to find someone who has used these evaluator scripts to get at the underlying data so I can see a working sample.  I searched for hours on the web and could find nothing other than the link I gave above.  Everyone else trying it ran into problems.  I tried to call ESRI today, but with a student license, they wouldn't talk to me (I'm trying to get permission through the University).

0 Kudos
MelindaMorang
Esri Regular Contributor

0 is not equivalent to Null in this case.  You would have to check "is null" or just "if not value".

This might be a stupid question, but after you made the changes to your evaluator, did you re-build the network?  If not, it won't have picked up any of the changes, so you would still get the same error as before.

0 Kudos