3

I'm having a frustrating time trying to use the Create TIN tool within Python, when the input featureclass name is a variable.

The help file entry for Create TIN shows a hard-coded path to the featureclass "points.shp" in the stand-alone example:

arcpy.CreateTin_3d("NewTIN", "....prj", "points.shp Shape.Z masspoints")

The script example uses {0}:

arcpy.ddd.CreateTin(outTin, sr, "{0} Shape.Z masspoints" .format(lasMP), "Delaunay")

It's unclear to me what the {0} represents (the first argument? - what if I don't have an argument, but only have access to a variable?).

The syntax section of the help file shows that the in_features can be specified as an array (of arrays?):

[[in_feature_class, height_field, SF_type, tag_value],...]

but I can't get this to work - it returns a generic "ERROR 999999: Error executing function".

So my question is, how can I use a variable as the featureclass name in the CreateTIN tool within Python?

Here is my non-functioning code:

fc = "path_to_featureClass"
tin = "path_to_output_TIN"
sr = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"

arcpy.CreateTin_3d(tin, sr, [fc + "fieldName Hard_Line <None>"], "DELAUNAY")

(where I have valid paths to fc and tin, and fieldName is a valid field on the layer.) I can successfully create a TIN using this dataset when using the tool manually.

  • 1
    Have you tried running it manually and then using Copy As Python Snippet to snag the syntax from the Geoprocessing | Results window. – PolyGeo Apr 1 '14 at 6:44
  • @PolyGeo I tried exporting from a model - this sets a variable for the FC, but ignores this and uses the full FC path in the CreateTIN line anyway... – Stephen Lead Apr 1 '14 at 23:38
  • 1
    As mentioned by @blah238 earlier today in answer to another question, the export from model to Python/ArcPy is quite flawed blogs.esri.com/esri/arcgis/2011/06/24/exportmodeltopy I suspect Copy As Python Snippet may do a better job but have not tested your example. – PolyGeo Apr 2 '14 at 0:03
2

Your code looks almost like mine but I don't use brackets for the Value Table and use {}.format for variable substitution:

import arcpy

arcpy.CheckOutExtension("3D")
fc = r"C:/GIS/Temp/test.gdb/Points3D"
tin = r"C:/Users/user/Documents/ArcGIS/CreateTin5"
sr = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
in_field = "ELEVATION"

arcpy.CreateTin_3d(tin,sr,"{0} {1} Mass_Points <None>".format(fc,in_field),"DELAUNAY")

{0} and {1} is a way to substitute the values with variables and you can use .format to specify the variables according to the index number -- sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.