When calculate the turn value in the network dataset, is Turn.Angle only useful with VB Script? How to edit a pre-logic script code with turn.angle using python language?
ArcMap Version: 10.4.0.5524
Code blocks in the normal sense, call a function using ! enclosing field names, I don't know if that is your case. You didn't look far enough down in the examples in the link I sent to see their example... so check it out and see if this matches your case.
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">somefunc</SPAN><SPAN class="punctuation token">(</SPAN>val<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> val<SPAN class="punctuation token">.</SPAN>Angle <SPAN class="operator token">></SPAN> <SPAN class="number token">270</SPAN><SPAN class="punctuation token">:</SPAN> turnTime <SPAN class="operator token">=</SPAN> <SPAN class="number token">10</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> turnTime <SPAN class="operator token">=</SPAN> <SPAN class="number token">20</SPAN> <SPAN class="keyword token">return</SPAN> turnTime <SPAN class="comment token"># use this in the value= segment</SPAN> somefunc<SPAN class="punctuation token">(</SPAN>!Turn!<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># if Turn is a field</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I want to add some logic for calculate the turn time with different turn angle.
For example:
This Script Evaluator expression is valid in VB Script:
If Turn.Angle > 270 Then turnTime = 10 Else turnTime = 20 End If
Value = turnTime
However this is not valid in python script.
if Turn.Angle > 270: turnTime = 10 else: turnTime = 20
I don't understand your wrong section... you can't assign to a variable there. The correct section, just takes the Turn and returns it's example. More complex examples Types of evaluators used by a network—Help | ArcGIS for Desktop show a def being used and a field name enclosed in double exclamation marked being used
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.