# -*- coding: utf-8 -*- # --------------------------------------------------------------------------- # Script.py # Generated by ArcGIS/ModelBuilder # Description: # --------------------------------------------------------------------------- # Import modules: import sys import arcpy # Local variables: arcpy.env.workspace = sys.path[0] # The directory the script was executed in. Alternative: "C:\\your_path" kmz = arcpy.ListFiles("*.KM*")[0] if len(arcpy.ListFiles("*.KM*")) > 0 else "your_file_name.kmz" gdb = arcpy.env.workspace pts = kmz.split(".")[0] + "\\Points" pts_strike_field = pts pts_strike_value = pts_strike_field pts_dip_field = pts_strike_value pts_dip_value = pts_dip_field # Process: KML To Layer arcpy.KMLToLayer_conversion(kmz, gdb) # Process: Add Field Strike arcpy.AddField_management(pts, "Strike", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field Strike arcpy.CalculateField_management(pts_strike_field, "Strike", "code(!Snippet!)", "PYTHON", "def code(text):\\n delim = \" / \"\\n defaultVal = 0\\n idx = 1\\n if delim not in text:\\n return defaultVal\\n else:\\n a = text.split(delim)[idx]\\n b = \"\".join(i for i in a if i.isdigit())\\n return int(b if len(b) > 0 else str(defaultVal))") # Process: Add Field Dip arcpy.AddField_management(pts_strike_value, "Dip", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field Dip arcpy.CalculateField_management(pts_dip_field, "Dip", "code(!Snippet!)", "PYTHON", "def code(text):\\n delim = \" / \"\\n defaultVal = 0\\n idx = 0\\n if delim not in text:\\n return defaultVal\\n else:\\n a = text.split(delim)[idx]\\n b = \"\".join(i for i in a if i.isdigit())\\n return int(b if len(b) > 0 else str(defaultVal))")