Convert Network Dataset Evaluators from VBA to Python

200
6
Jump to solution
08-17-2017 08:28 AM
Highlighted
Occasional Contributor III

I am working on converting all of the VBA script evaporators from VBA to Python, and for the life of me I can not get it to work. I understand python, but there is an element to using the script elevator this that I am missing/not understanding.

This is an example of the current VBA that works

Dim val 

val = 0

if(Edge.AttributeValueByName("network_participating)=0) then

val = -1

Based on this, and this, I came up with the code examples below (along with several others not listed) and nothing is working. What am I overlooking?

def NetworkParticipating(value):
  value = 0
  if Edge.AttributeValueByName(value)== 0:
    value = -1
  return value

Value = NetworkParticipating('!network_participating!')

##Also tried:

def NetworkParticipating(value):
  restricted = False
  if value = 0:
    restricted = True
  return restricted


Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Going by your original VBA, and what Melinda suggested, try this modification:

def NetworkParticipating(value):
   if Edge.AttributeValueByName( value) == 0:
      return -1
   return 0

Value = NetworkParticipating("network_participating")

View solution in original post

Reply
0 Kudos
6 Replies
Highlighted
Esri Regular Contributor

Try something like this.

def NetworkParticipating(network_participating):
  if Edge.AttributeValueByName(network_participating)== 0:
    return -1
  return 0

Value = NetworkParticipating('!network_participating!')‍‍‍‍‍‍

The problem with your attempt was that you were passing '!network_participating!' to the function but then immediately reassigning the variable to something else.

Highlighted
Occasional Contributor III

Thank you for the suggestion Melinda, but it didn't work. I also tried:

def NetworkParticipating(value):
  if Edge.AttributeValueByName(value)== 0:
    restricted = True
  else:
    restricted = False
  return restricted

Value = NetworkParticipating('!network_participating!')
‍‍‍‍‍‍‍‍
##And I tried

def NetworkParticipating(value):
  if value == 0:
    restricted = True
  else:
    restricted = False
  return restricted

Value = NetworkParticipating('!network_participating!')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Reply
0 Kudos
Highlighted
Esri Regular Contributor

Let's back up.  Can you describe in words what you're trying to do?

Reply
0 Kudos
Highlighted
Occasional Contributor III

Melinda - You were on the right track - Jay's slight modification to the Value field did the trick. Thank you for your time & input.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Going by your original VBA, and what Melinda suggested, try this modification:

def NetworkParticipating(value):
   if Edge.AttributeValueByName( value) == 0:
      return -1
   return 0

Value = NetworkParticipating("network_participating")

View solution in original post

Reply
0 Kudos
Highlighted
Occasional Contributor III

Thanks Jay - That worked. Although I'm a bit perplexed since typically python field names begin and end with '!' and the example of python script evaporators does as well. Any thoughts on this?

Reply
0 Kudos