1

I am selecting points from the map and roads and trying to join them based on my picks. It works in Jupyter notebook however it does not work in toolbox and I could not figure it out. I tried to convert it to table in order to make the operation but somehow it still does not work. Here is my code.

I also tried to make it work with CopyFeatures_management but still no luck.

Edit1: The join happens when using the code on the jupyter notebook and i can see the results and everything however if i do it by using toolbox there is no error but there is no join operation happening.

# -*- coding: utf-8 -*-
import arcpy
import os
class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = "toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [Tool]


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

    def getParameterInfo(self):
        """Define parameter definitions"""

        #Defining folder input in this part.
        input_folder = arcpy.Parameter(
            name='input_folder',
            displayName='Input Folder',
            datatype='DEWorkspace',
            direction='Input',
            parameterType='Required')

        params = [input_folder]

        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."""

        #Defining parameter with corresponding values.
        input_folder_location = parameters[0].value

        arcpy.env.workspace = input_folder_location
        arcpy.env.overwriteOutput = True

        arcpy.CopyRows_management("Building",  "selected_building")
        arcpy.MakeTableView_management("selected_building", "view_selected_building")
        arcpy.CopyRows_management("Road",  "selected_road")
        arcpy.MakeTableView_management("selected_road", "view_selected_road")
        arcpy.management.AddJoin("view_selected_building",'OBJECTID', "view_selected_road", "OBJECTID", "KEEP_ALL")
    #it does not work till this part. I tried can make it work in jupyter notebook  
    #if it works i would like to join it back to the main "Building"

        return

1
  • 1
    Please Edit the question to clarify what "does not work" means, to include an error message or actual behavior. You can add diagnostic outputs using messages.addMessage().
    – Vince
    Jun 16, 2021 at 10:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.