Select to view content in your preferred language

Convert Network Dataset Evaluators from VBA to Python

991
6
Jump to solution
08-17-2017 08:28 AM
RachelAlbritton
Frequent Contributor

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)
0 Kudos
1 Solution

Accepted Solutions
JaySandhu
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

0 Kudos
6 Replies
MelindaMorang
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.

RachelAlbritton
Frequent Contributor

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!')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
MelindaMorang
Esri Regular Contributor

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

0 Kudos
RachelAlbritton
Frequent Contributor

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

0 Kudos
JaySandhu
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")

0 Kudos
RachelAlbritton
Frequent Contributor

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?

0 Kudos