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
Solved! Go to Solution.
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")
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.
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!')
Let's back up. Can you describe in words what you're trying to do?
Melinda - You were on the right track - Jay's slight modification to the Value field did the trick. Thank you for your time & input.
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")
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?