2

I have created a python toolbox arcgiscontroller.pyt:

class Toolbox(object):
def __init__(self):
    self.label = "ArcGisController"
    self.alias = ""
    self.tools = [AddUpdateFeatureClasses]

class AddUpdateFeatureClasses(object):
def __init__(self):
    self.label = "AddUpdateFeatureClasses"
    self.description = ""
    self.canRunInBackground = True

def getParameterInfo(self):
    param0 = arcpy.Parameter(displayName="Input Json", name="inJson", datatype="GPString", parameterType="Required", direction="Input")
    param1 = arcpy.Parameter(displayName="Output Json",name="outJson",datatype="GPString",parameterType="Derived",direction="Output")
    params = [param0, param1]
    return params

def execute(self, parameters, messages):
  import os
  # This can be removed once the arcgiscontroller is installed into the python path
  import sys
  sys.path.insert(0, r"C:\mypythonpath")
  from {mycustompackages} import ArcGisController
  if __name__ == "__main__":
    ArcGisController.run()
  return

In the called code (in ArcGisController.run():), I try to get the input json like this:

class ArcGisController(object):
    def __init__(self):
        *initialization stuff*
    def processInput(input):
        *do stuff* 

    @staticmethod             
    def run():
        # get input parameters
        inJson = arcpy.GetParameterAsText(0)
        processInput(inJson)
        return result

but the arcpy.GetParameterAsText call returns ' '.

Does anyone know what I can do to be able to retrieve the input json in the called code? The ArcGisController.run() code works fine when I manually create a toolbox, so I'm guessing that part is fine and the problem lies within my python tool code.

My goal is to automate the publishing of this GP tool.

  • 1
    What is the exact syntax of your call to ArcGisController.run()? Are you actually passing the parameter to it or is it being ignored in the call? – Michael Stimson Mar 16 '17 at 22:31
  • I am calling it with that exact syntax: ArcGisController.run(). I am not passing any parameters to it, but trying to retrieve the input given to the python tool with arcpy.GetParamaeterAsText – calk93 Mar 16 '17 at 22:33
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. Note I have edited your code slightly to make it a little shorter to read. I removed un-called empty functions – Midavalo Mar 16 '17 at 22:34
  • Are you expecting inJson = arcpy.GetParameterAsText(0) to receive the value in param0 = arcpy.Parameter()? – Midavalo Mar 16 '17 at 22:48
  • Yes, that is what i wanted it to do. – calk93 Mar 16 '17 at 22:51
2

You need your ArcGisController.run() to request the input value

@staticmethod             
def run(inJson):
    # get input parameters
    processInput(inJson)
    return result

And in your python toolbox pass the param0 value when you call run():

def getParameterInfo(self):
    param0 = arcpy.Parameter(displayName="Input Json", name="inJson", datatype="GPString", parameterType="Required", direction="Input")
    param1 = arcpy.Parameter(displayName="Output Json",name="outJson",datatype="GPString",parameterType="Derived",direction="Output")
    params = [param0, param1]
    return params

def execute(self, parameters, messages):
    import os
    # This can be removed once the arcgiscontroller is installed into the python path
    import sys
    sys.path.insert(0, r"C:\mypythonpath")
    from {mycustompackages} import ArcGisController
    if __name__ == "__main__":
        ArcGisController.run(parameters[0].valueAsText)
    return

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.