Select to view content in your preferred language

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

4495
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
MelindaMorang
Esri Regular Contributor

Did you remember to switch the language picker to python instead of VBScript?

0 Kudos
BradSrebnik
Occasional Contributor

Yes it is set to Python and "Verify" is successful.

0 Kudos
MelindaMorang
Esri Regular Contributor

Oops, sorry, just realized I told you wrong earlier.  Don't use "is not null".  Use "is not None".  Sorry, my brain got python and Javascript garbled together.

0 Kudos
BradSrebnik
Occasional Contributor

Thanks!!!  That works!  (Note:  It looks like the total cost variable can get to be too big, but I can scale it so it stays in range.)

0 Kudos
MelindaMorang
Esri Regular Contributor

Are you able to share your data?  If so, please zip up your entire gdb and post it somewhere I can download, and I can take a look.

Otherwise, honestly at this point you might really need to contact Support, if you're able.  This question is getting pretty complicated, and they would be better equipped to walk you through the process.

0 Kudos
BradSrebnik
Occasional Contributor

Thanks.  I'll see if I can select out a small portion of the data and zip it up.  I cannot get support through my student license.

Note:  If I change the script to this:

def SetCost(lim):
    cost=10000
    if lim is not null:
        cost=lim*lim
    return cost

I only get an error on one object - the one that has a null for the speed limit.  So my workaround is probably to select only the objects that have all the values I need, and ignore road segments that don't.  I thought that was the correct syntax for checking for null but I'll try to confirm that.

0 Kudos
CarlosRibeiro
Occasional Contributor

Dear Brad,

try  if lim is not None

0 Kudos