Writing Geometries - how do I adapt code to create an M-aware polyline with attribute

Discussion created by woodlandbury on Mar 2, 2012
This is an ArcGIS 10 query.  I am attempting to create an M-aware polyline features that is spatially referenced and takes input from coordinates in a text file. 
The text input is in the following format: ID,X,Y,M

I would like to write the ID value to be the Route Reference in the m-aware polyline.
Grateful for any help.

# Import system modules
import arcpy
from arcpy.sa import *
import sys
import fileinput
import string
import os

arcpy.env.overwriteOutput = True

# Variable Declarations:
infile = arcpy.GetParameterAsText(0)
routes = arcpy.GetParameterAsText(1)
template = arcpy.GetParameterAsText(2)
prjFile = r"C:\MODEL\CoordinateSystems\WGS 1984 UTM Zone 31N.prj"
spatialRef = arcpy.SpatialReference(prjFile)

# PROCESS: Create route features
# Routes are M-Aware Polyline features

   # Create the output feature class
                                       "Polyline", template)

   # Open an insert cursor for the new feature class
   cur = arcpy.InsertCursor(routes,spatialRef)

   # Create an array and point object needed to create features
   lineArray = arcpy.Array()
   pnt = arcpy.Point()

   # Initialize a variable for keeping track of a feature's ID.
   ID = -1
   for line in fileinput.input(infile): # Open the input file
      # set the point's ID, X and Y properties
      pnt.ID, pnt.X, pnt.Y, pnt.M = string.split(line,";")
      print pnt.ID, pnt.X, pnt.Y, pnt.M
      if ID == -1:
         ID = pnt.ID

      # Add the point to the feature's array of points
      # If the ID has changed, create a new feature
      if ID != pnt.ID:
         # Create a new row or feature, in the feature class
         feat = cur.newRow()

         # Set the geometry of the new feature to the array of points
         feat.shape = lineArray

         # Insert the feature
      ID = pnt.ID

   # Add the last feature
   feat = cur.newRow()
   feat.shape = lineArray
   del cur
except Exception as e:
   print e.message