3

I updated the code in the script below per suggestion. I receive the same results as described in my original post, here...

I have a very simple Modelbuilder model (ArcGIS Pro, v2.6) that has a parameter for user input asking how many input feature classes to include (in a later model). I want the user to be able to input a number between 1-4 (AuxNum). If the user input value is 1 then a specific model runs, if the user input is 2 then a different model runs, and so on. Prior to the chosen model running, the user needs to be able to input parameter values prior to the model running. I want the python code to open the second model in the Geoprocessing window to allow the user to input parameters.

Here is the layout of the first user input model.

First model user input layout.

In the DecideAuxLayer tool in the above model layout, I have the following Python code, (spoiler alert!! I'm not a coder).

  • Toolbox is PreProcesses.tbx

  • Model names are Aux1, Aux2, Aux3, Aux4

  • Models and python script are inside PreProcesses.tbx

  • Toolbox, models, and .py are all located in C:\Temp

import arcpy
arcpy.AddToolbox("C:/Temp/PreProcesses.tbx")
AuxNum = arcpy.GetParameterAsText(0)
if (AuxNum is 1):
    arcpy.Aux1_PreProcesses()
elif (AuxNum is 2):
    arcpy.Aux2_PreProcesses()

Issue: when I run the Python script the model does not open in the Geoprocessing window. The model completes with no errors or warnings and shows that the input value is 1. That's it. Here is a screenshot of the results of the script model.

Model run results, not what I'm looking for!

  • 4
    Does this answer your question? Run model from python .. module object not callable – Hornbydd Aug 5 at 18:07
  • I tried the suggestion you link to with the same model run results, using this code, import arcpy arcpy.ImportToolbox("C:/Temp/PreProcesses.tbx") AuxNum = arcpy.GetParameterAsText(1) if (AuxNum is 1): arcpy.Aux1_PreProcesses() elif (AuxNum is 2): arcpy.Aux2_PreProcesses() – Geoffrey Whitchurch Aug 5 at 20:10
  • Geoffrey, don't put your adjusted code in a comment it is unreadable! Spacing in python language is critical and no one can tell if the issue is with that. Amend your question to show what you have done. That is what is expected by the forum and is encouraged as you have more control over formatting. – Hornbydd Aug 6 at 13:26
  • 1
    Thank you for your friendly pointers. I have updated the code in the original post and am getting the same result as before. – Geoffrey Whitchurch Aug 6 at 17:01
1

I believe the issue is to do with how you are testing the variable AuxNum. Your code returns the parameter value as a TEXT. You then test the TEXT variable with AuxNum is 1, is your TEXT a number...no! You then test if your TEXT variable is another number...which again is no! and thus nothing happens. You need to adjust your code to this:

(AuxNum == '1')

Now you are testing if your text variable is equal to the text '1'.

UPDATE

@GeoffreyWhitchurch so I spoofed up your scenario and it worked for me. Looking at your screen shots your parameter feeding into the script has a dotted line, that indicates a precondition and not a parameter feeding into the script tool. Did you create a parameter for the script tool? It's not enough to write code that accepts a parameter you need to actually define them in the properties of the tool so they expose as inputs to the tool in modelbuilder.

setting scripts parameters

import arcpy
arcpy.AddToolbox("C:/Temp/PreProcess.tbx")
AuxNum = arcpy.GetParameterAsText(0)
if (AuxNum == '1'):
    arcpy.aux1_PreProcess()
elif (AuxNum == '2'):
    arcpy.aux2_PreProcess()

UPDATE

@Hornbydd See error in image below. Made slight spelling change to "...Preprocesses" in the code, I include the code as I entered it for this error message.

import arcpy
arcpy.AddToolbox("C:\Temp\PreProcesses.tbx")
AuxNum = arcpy.GetParameterAsText(0)
if (AuxNum == '1'):
    arcpy.Aux1_PreProcesses()
elif (AuxNum == '2'):
    arcpy.Aux2_PreProcesses()

enter image description here

| improve this answer | |
  • I tried what you suggest and get the exact same result: after the tool runs, in the View Details windows of the Geoprocessing tool it reports that the tool ran successfully and verifies that my AuxNum value is correct. The AuxNum value does change in the details view corresponding to the value I set as the parameter (1 or 2). – Geoffrey Whitchurch Aug 7 at 14:08
  • @GeoffreyWhitchurch see update in answer. – Hornbydd Aug 7 at 17:42
  • Have you recently updated arcpro from 2.5 to 2.6? I had to uninstall arcpro and install 2.6 so I could clone the python environment. I was getting similar errors. – Hornbydd Aug 7 at 19:40
  • I'm not sure which updated code you are referring to, but the above scripts have the same issues as referenced by each. Yes, I recently updated to 2.6. – Geoffrey Whitchurch Aug 10 at 14:02

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.