<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Writing from/to Z values from fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573505#M44924</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should also put in a test to check the assumption that the line only has 2 vertices. For lines with more than 2 vertices, the resultant 3D line with start and end Z values set will look very wonky since any intermediate vertices will have no Z value.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 May 2014 03:29:37 GMT</pubDate>
    <dc:creator>TimBarnes</dc:creator>
    <dc:date>2014-05-19T03:29:37Z</dc:date>
    <item>
      <title>Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573501#M44920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have some Z-enabled lines that have no values currently set in the Z property, however I have FromLevel and ToLevel fields as attributes in the feature class.&amp;nbsp; I'd like to have a script that loops through all my lines and populates the Start Vertex with the value in the "FromLevel" field, and the End Vertex with the value in the "ToLevel" field.&amp;nbsp; Is this possible?&amp;nbsp; I started playing around with an UpdateCursor as I thought this would be the quickest/easiest way to get it done, but am unsure how to write to the Z property through the UpdateCursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using ArcGIS Desktop 10.2.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, sys, string, os, fpformat&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd)&amp;nbsp; for layer in layers:&amp;nbsp; &lt;FONT face="Consolas"&gt;&amp;nbsp; if layer.name == "3dLine": &amp;nbsp;&amp;nbsp;&amp;nbsp; layerexists = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ["SHAPE@Z","FromLevel","ToLevel"]&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if layerexists == 1: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strLineFC = "3dLine"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineRows = arcpy.da.UpdateCursor(strLineFC, fields)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineRow = lineRows.next()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while lineRow: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; linePointsArray = lineRow.Shape.getPart(0) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_count = linePointsArray.count &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_begin = linePointsArray.next() # First Vertex on line&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = row[1] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vertices = 2&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while vertices &amp;lt; pt_count: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_end = linePointsArray.next() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vertices = vertices + 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_end = linePointsArray.next() # Last Vertex on line &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = row[2]&lt;/FONT&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This tells me there is no Shape property to get the vertex info from... (this script was butchered from another similar script, however that script writes to an attribute, not the Z property, and uses arcpy.updatecursor not arcpy.da.updatecursor.&amp;nbsp; Can I write to the Z property through the arcpy.updatecursor?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd appreciate any tips/suggestions to allow me to do this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 May 2014 23:01:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573501#M44920</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-18T23:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573502#M44921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Apologies, a lot of the indentation has disappeared in the CODE block above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 May 2014 23:02:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573502#M44921</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-18T23:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573503#M44922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I have some Z-enabled lines that have no values currently set in the Z property, however I have FromLevel and ToLevel fields as attributes in the feature class.&amp;nbsp; I'd like to have a script that loops through all my lines and populates the Start Vertex with the value in the "FromLevel" field, and the End Vertex with the value in the "ToLevel" field.&amp;nbsp; Is this possible?&amp;nbsp; I started playing around with an UpdateCursor as I thought this would be the quickest/easiest way to get it done, but am unsure how to write to the Z property through the UpdateCursor.&lt;BR /&gt;&lt;BR /&gt;I'm using ArcGIS Desktop 10.2.2&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, sys, string, os, fpformat&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd)&amp;nbsp; for layer in layers:&amp;nbsp; &lt;FONT face="Consolas"&gt;&amp;nbsp; if layer.name == "3dLine": &amp;nbsp;&amp;nbsp;&amp;nbsp; layerexists = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ["SHAPE@Z","FromLevel","ToLevel"]&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if layerexists == 1: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strLineFC = "3dLine"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineRows = arcpy.da.UpdateCursor(strLineFC, fields)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineRow = lineRows.next()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while lineRow: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; linePointsArray = lineRow.Shape.getPart(0) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_count = linePointsArray.count &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_begin = linePointsArray.next() # First Vertex on line&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = row[1] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vertices = 2&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while vertices &amp;lt; pt_count: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_end = linePointsArray.next() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vertices = vertices + 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt_end = linePointsArray.next() # Last Vertex on line &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = row[2]&lt;/FONT&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;This tells me there is no Shape property to get the vertex info from... (this script was butchered from another similar script, however that script writes to an attribute, not the Z property, and uses arcpy.updatecursor not arcpy.da.updatecursor.&amp;nbsp; Can I write to the Z property through the arcpy.updatecursor?&lt;BR /&gt;&lt;BR /&gt;I'd appreciate any tips/suggestions to allow me to do this.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Mike.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You cannot write to the coordinate properties of a polyline without rewriting the entire polyline geometry.&amp;nbsp; You have to convert the polyline to a point array.&amp;nbsp; You can modify the coordinate properties of the points in the array and write use that array to overwrite the polyline geometry.&amp;nbsp; Frankly there is no good help on how to do this and ESRI should provide a real example of how to modify a geometry other than a point geometry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code below is based on &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/94295-Move-Features?highlight=arcpy+modify+polyline+geometry" rel="nofollow" target="_blank"&gt;post number 6 of this post from Matthew Coyle&lt;/A&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/96195-Change-Z-coordinates-of-vertexes-by-UpdateCursor?highlight=multipart+array" rel="nofollow" target="_blank"&gt;post number 4 of this post by Xander Bakker&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; The code is untested and I am not sure if my method of attempting to find the first and last points is going to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; infc = arcpy.GetParameterAsText(0) # the input line feature class&amp;nbsp; # Enter for loop for each feature # with arcpy.da.UpdateCursor(infc, ["SHAPE@", "FromLevel", "ToLevel"]) as update_cursor: for row in update_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; array = arcpy.Array() &amp;nbsp;&amp;nbsp;&amp;nbsp; partNum = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp; firstpnt = row[0].firstPoint &amp;nbsp;&amp;nbsp;&amp;nbsp; lastpnt = row[0].lastPoint &amp;nbsp;&amp;nbsp;&amp;nbsp; pntnum = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp; for part in row[0]: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr = arcpy.Array() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for pnt in part: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pnt: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if partNum == 0 and firstpnt == pnt: # Modify Z value of the first point &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt.Z = row[1] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if partNum == lastpart - 1 and lastpnt == pnt: # Z value of the last point &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt.Z = row[2] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr.add(point) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.add(partArr) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partNum += 1 &amp;nbsp;&amp;nbsp;&amp;nbsp; new_line = arcpy.Polyline(array) &amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = new_line &amp;nbsp;&amp;nbsp;&amp;nbsp; update_cursor.updateRow(row)&amp;nbsp; del update_cursor&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 01:03:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573503#M44922</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-05-19T01:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573504#M44923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This code will only work if your polylines have no true curves.&amp;nbsp; True curves would be destroyed by this code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 01:39:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573504#M44923</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-05-19T01:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573505#M44924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should also put in a test to check the assumption that the line only has 2 vertices. For lines with more than 2 vertices, the resultant 3D line with start and end Z values set will look very wonky since any intermediate vertices will have no Z value.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 03:29:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573505#M44924</guid>
      <dc:creator>TimBarnes</dc:creator>
      <dc:date>2014-05-19T03:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573506#M44925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You cannot write to the coordinate properties of a polyline without rewriting the entire polyline geometry.&amp;nbsp; You have to convert the polyline to a point array.&amp;nbsp; You can modify the coordinate properties of the points in the array and write use that array to overwrite the polyline geometry.&amp;nbsp; Frankly there is no good help on how to do this and ESRI should provide a real example of how to modify a geometry other than a point geometry.&lt;BR /&gt;&lt;BR /&gt;The code below is based on &lt;A href="http://forums.arcgis.com/threads/94295-Move-Features?highlight=arcpy+modify+polyline+geometry" rel="nofollow noopener noreferrer" target="_blank"&gt;post number 6 of this post from Matthew Coyle&lt;/A&gt; and &lt;A href="http://forums.arcgis.com/threads/96195-Change-Z-coordinates-of-vertexes-by-UpdateCursor?highlight=multipart+array" rel="nofollow noopener noreferrer" target="_blank"&gt;post number 4 of this post by Xander Bakker&lt;/A&gt;.&amp;nbsp; The code is untested and I am not sure if my method of attempting to find the first and last points is going to work.&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Hi Richard,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your reply.&amp;nbsp; I couldn't get your code to work, but you moved me in the right direction.&amp;nbsp; I rewrote my code based on yours and the two posts you linked, and got it to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, fpformat
targetLayer = "MyLayer"
shapeFieldName = 'SHAPE'


cursor = arcpy.UpdateCursor(targetLayer)
for row in cursor:
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row.getValue(shapeFieldName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fromLevel = fpformat.fix(row.FromLevel,2) # Round levels 
&amp;nbsp;&amp;nbsp;&amp;nbsp; toLevel = fpformat.fix(row.ToLevel,2) # Round levels 
&amp;nbsp;&amp;nbsp;&amp;nbsp; geomArr = arcpy.Array()
&amp;nbsp;&amp;nbsp;&amp;nbsp; for part in geom:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr = arcpy.Array()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt_count = part.count # Count Vertices
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntNum = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for pnt in part:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pnt:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pntNum == 0: # Start Point (first vertex)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntOut = arcpy.Point(pnt.X, pnt.Y, fromLevel)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr.add(pntOut)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntNum = pntNum + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif pntNum == (pnt_count - 1): # End Point (last vertex)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntOut = arcpy.Point(pnt.X, pnt.Y, toLevel)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr.add(pntOut)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntNum = pntNum + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif pntNum &amp;lt; (pnt_count - 1): # Any additional vertices
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntOut = arcpy.Point(pnt.X, pnt.Y, pnt.Z)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partArr.add(pntOut)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pntNum = pntNum + 1


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomArr.add(partArr)


&amp;nbsp;&amp;nbsp;&amp;nbsp; polyline = arcpy.Polyline(geomArr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(shapeFieldName, polyline)
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Error " + str(row.objectid))

del row
del cursor
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:41:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573506#M44925</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2021-12-12T00:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573507#M44926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This code will only work if your polylines have no true curves.&amp;nbsp; True curves would be destroyed by this code.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully I don't &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I don't know of any, but since most of my data comes from external sources there may be some.&amp;nbsp; I'll check though, thanks for the tip.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 18:55:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573507#M44926</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-19T18:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573508#M44927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You should also put in a test to check the assumption that the line only has 2 vertices. For lines with more than 2 vertices, the resultant 3D line with start and end Z values set will look very wonky since any intermediate vertices will have no Z value.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Thanks Tim, I've put in a check for extra vertices and at this stage I'm only putting the Z onto the start/end, however if it becomes an issue I may need to interpolate the values in between.&amp;nbsp; That'll be my next problem I guess &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 18:56:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573508#M44927</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-19T18:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573509#M44928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hopefully I don't &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I don't know of any, but since most of my data comes from external sources there may be some.&amp;nbsp; I'll check though, thanks for the tip.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Mike.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the data comes as shapefiles there are no true curves.&amp;nbsp; True curves would only be created and preserved in a geodatabase.&amp;nbsp; But it is a potential gotcha if you ever do work with geodatabase true curves.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 18:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573509#M44928</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-05-19T18:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573510#M44929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks Tim, I've put in a check for extra vertices and at this stage I'm only putting the Z onto the start/end, however if it becomes an issue I may need to interpolate the values in between.&amp;nbsp; That'll be my next problem I guess &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Mike.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Interpolating Z values should be done with caution.&amp;nbsp; The elevations at the end points of a line may have no relation to the elevations in the center if the feature is long enough and goes through an area with severe terrain changes.&amp;nbsp; if you have surface elevation data it is best to use 3D Analyst tools to assign Z values.&amp;nbsp; The code could still provide a way to traverse the Z assignments to identify unexpected terrain configurations affecting your lines, which may indicate misalignment between the terrain data and the lines.&amp;nbsp; You should at least consider using the 3D Analyst extension tool set if you are going to work with elevation very much, since it will probably make many tasks much easier.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also if your field data is ever created from GPS points it is best to get each separate point with its XYZ coordiinates and build your lines from the raw GPS data rather than from fields associated with your line data and interpolation.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 19:09:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573510#M44929</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-05-19T19:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573511#M44930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Interpolating Z values should be done with caution. &lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Thanks for your caution.&amp;nbsp; The datasets I am working with are sewer pipes, so they don't have a direct relation to the actual terrain (other than being below the terrain elevation).&amp;nbsp; Interpolation in this situation should work for most of the lines where required I think &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 20:00:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573511#M44930</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-19T20:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573512#M44931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;If the data comes as shapefiles there are no true curves.&amp;nbsp; True curves would only be created and preserved in a geodatabase.&amp;nbsp; But it is a potential gotcha if you ever do work with geodatabase true curves.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Most of our third party data comes from AutoCAD DWG file, which I think does also allow for curves.&amp;nbsp; We shouldn't have many/any though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 20:01:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573512#M44931</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2014-05-19T20:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Writing from/to Z values from fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573513#M44932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for your caution.&amp;nbsp; The datasets I am working with are sewer pipes, so they don't have a direct relation to the actual terrain (other than being below the terrain elevation).&amp;nbsp; Interpolation in this situation should work for most of the lines where required I think &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Mike.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For pipeline data I agree that interpolation will more than likely work, since line breaks are probably being made where changes related to gravity flow occur.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 20:49:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-from-to-z-values-from-fields/m-p/573513#M44932</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-05-19T20:49:28Z</dc:date>
    </item>
  </channel>
</rss>

