0

been writing a toolbox to speed up my work and I've run into a strange issue. My start well tool works fine, but my add surveys tool does not and causes ArcGIS Pro 2.1 to crash.

I'll post the code below and a github link to download the toolbox.

[GitHub Link][1][1]: https://github.com/tpubben/wellsitetools

import arcpy

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "WellsiteTools"
        self.alias = "Wellsite Geo Tools"

        # List of tool classes associated with this toolbox
        self.tools = [StartWellTool, AddSurveyTool]


class AddSurveyTool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Add Surveys"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
            displayName='Select Well',
            name='wellSelect',
            datatype='DEFeatureClass',
            parameterType='Required',
            direction='Input'
        )

        param1 = arcpy.Parameter(
            displayName='Survey File',
            name='surFile',
            datatype='DETextfile',
            direction='Input',
            parameterType='Optional'
        )

        param2 = arcpy.Parameter(
            displayName='Survey Column Order',
            name='colOrder',
            datatype='GPValueTable',
            parameterType='Optional',
            direction='Input'
        )

        param3 = arcpy.Parameter(
            displayName='Coordinate System',
            name='coordSys',
            datatype='GPSpatialReference',
            parameterType='Required',
            direction='Input'
        )

        params = [param0, param1, param2, param3]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        well_file = parameters[0].valueAsText
        sur_file = parameters[1].valueAsText
        col_list = parameters[2].valueAsText.split(';')
        utmdat = parameters[3].valueAsText
        # set variables for each column
        m, t, n, e = int(col_list[0][-1]) - 1, int(col_list[1][-1]) - 1, 
              int(col_list[2][-1]) - 1, int(col_list[3][-1]) - 1
        # create a search cursor to pull the info out of the config file
        inp_rows = arcpy.SearchCursor(well_file, fields='wellName; UWI; 
              KBElev; utmE; utmN; UTMDat')

        for row in inp_rows:
            utmE = row.getValue('utmE')
            utmN = row.getValue('utmN')
            kbElev = row.getValue('KBElev')
            uwi = row.getValue('UWI')


        # after parameters are set
        with open(sur_file, 'r') as sf:
            sl = []
            # read lines in provided survey file and find only the ones with 
            # survey data
            for line in sf:
                line = line.strip().split()
                if len(line) > 0 and line[0][0].isdigit():
                    sl.append(line)

        # create feature class for points
        tpm_points = 'p_' + uwi
        arcpy.CreateFeatureclass_management(parameters[5].valueAsText, 
                tpm_points, 'POINT', has_z='ENABLED', 
                spatial_reference=utmdat)
        arcpy.management.AddFields(tpm_points, [['MD', 'DOUBLE', 'MD', 
                None]])
        arcpy.management.AddFields(tpm_points, [['TVD', 'DOUBLE', 'TVD', 
                None]])
        arcpy.management.AddFields(tpm_points, [['EAST', 'DOUBLE', 'NORTH', 
                None]])
        arcpy.management.AddFields(tpm_points, [['NORTH', 'DOUBLE', 'EAST', 
                None]])

        # continue on with assigning each column to the appropriate value
        fields = ['MD', 'TVD', 'EAST', 'NORTH']
        cursor = arcpy.da.InsertCursor(tpm_points, ['MD', 'TVD', 'EAST', 
                'NORTH', 'SHAPE@Z', 'SHAPE@XY'])
        for item in sl:
            # m, t, n, e were defined from parameter 8
            md, tvd, east, north = float(item[m]), float(item[t]), 
                float(item[e]), float(item[n])
            surveys = [md, utmE + east, utmN + north, kbElev - tvd, (utmE + 
                east, utmN + north)]
            cursor.insertRow(surveys)

        arcpy.PointsToLine_management(tpm_points, 'w_' + uwi)
        # delete temp point feature
        # arcpy.Delete_management(tpm_points)
        # add surveys to map
        return
  • when does it crash, when you try to open the tool or when you add/remove parameters? – NULL.Dude Jun 15 '18 at 16:12
  • When I open the tool – tpubbsGIS Jun 15 '18 at 19:22
  • I tried this in ArcGIS Pro 2.1.3 and it opened without issue. What version are you running? – Evil Genius Jul 6 '18 at 19:47
0

Although you have developed this for Pro I opened it up in ArcMap. It was throwing syntax errors on the lines that you have split across multiple lines and introduced indentations. With some simple deletion to ensure code is all on one line it worked for me.

One of the offending lines was, see how you have indented it:

m, t, n, e = int(col_list[0][-1]) - 1, int(col_list[1][-1]) - 1, 
              int(col_list[2][-1]) - 1, int(col_list[3][-1]) - 1
  • That's actually the way stack exchange split it up. But thanks for looking at it anyway. It must be a bug with one of the functions in ArcPro because it does work in ArcMap. – tpubbsGIS Jun 16 '18 at 0:30

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.