This is what I am looking for:

  1. Create two tools in Python Toolbox: Tool1 and Tool2 (I am able to do that)
  2. I want to define a parameter in Tool2 whose value depends on parameter entered by user in Tool1.

How can I do that? Can Tool1 be called in Tool2 and automatically Tool2 gets the value of parameter entered by user in Tool1? I want to use the value of parameter entered by user in Tool1 to define a workspace in def getParameterInfo(self): in Tool2.

  • You could write it out to a text file and go looking for it with tool 2 in the validator then read the text file... use the TEMP environment variable for the text file location... or alternately set an environment variable and read it.. I wouldn't do that too often as system variables aren't something to be written frivolously. – Michael Stimson Aug 27 '15 at 23:59
  • Thanks Michael. Could you elaborate on that little more? What to write to text file? – Mony Aug 28 '15 at 0:13
  • As the tools cannot be made 'aware' of each other you need a 3rd party to hold onto the value. For this a text file is a viable solution where the first one writes to the file the value that needs to be passed and the second reads it and populates the box. For this to work the 2nd tool needs to be opened after the box on the 1st tool is populated. – Michael Stimson Aug 28 '15 at 0:17
  • Isn't this the same as or just a continuation of your earlier question? In which case I think you should edit the original to revise that rather than spawning this duplicate. I've used text files to pass values between a Python AddIn and Python Toolbox tools that it calls successfully but between your two questions it sounds like what you are trying to do is a use case for tool validation so I think you should explore that first. – PolyGeo Aug 28 '15 at 0:24
  • There is a Q&A at gis.stackexchange.com/questions/126846/… that may be worth you reviewing. – PolyGeo Aug 28 '15 at 0:37

One solution would be to create a model in ModelBuilder. You can drag and drop your two tools into the model and then connect them how you like depending on your workflow i.e. output from Tool 1 becomes input for Tool 2.

If, as it sounds in your case, the user is specifying a parameter for Tool 1 which you want to also use in Tool 2, then in your model you can create a variable (Right-click in ModelBuilder window and select Create Variable), let's call it InVar, which will hold the users input. You will have to choose a type for this variable e.g. Feature Class, SQL Expression, Folder etc.

You can then connect this InVar to Tool 1 and Tool 2 and select which parameter it will become for each tool e.g. Output Dataset, Expression, Output Folder. This will depend on what you're parameters are for your two tools.

Next you have to define the parameters for your model so that when run it prompts the user to assign values to these parameters via a dialogue box - just like other tools.

Right-click on a model element (e.g. Input/Output Dataset or InVar) and choose Model Parameter to make it a parameter - the letter 'P' will appear above the element. In this case, make InVar a parameter.

When happy with your model save it in a toolbox. To run the model double-click the tool you have just made and you will be presented with the usual dialogue box to enter your parameters.

As I don't know the details of your two tools or the workflow it's hard to go into too much detail but that's the gist of it.

For more information (and some tutorials) on ModelBuilder check out the ESRI Resource pages as they provide quite an in-depth look at model building: http://resources.arcgis.com/en/help/main/10.2/#/What_is_ModelBuilder/002w00000001000000/.


In the following graphic I have put together a model in which the output from a tool (Tool 1) becomes the input into another (Tool 2), and I created InVar, a workspace variable, as described above.

Then, using the Connect tool (enter image description here), I connected InVar to Tool 1 and Tool 2. Since you mention that you wanted InVar to become the workspace environment variable in Tool 2, I selected Environments - Current Workspace when making the connection (as shown in the graphic).

Additionally, I have made Invar and InFeatures Model Parameters as described previously.

enter image description here

| improve this answer | |
  • Thanks. Yes, I tried. But how to declare the InVar in Tool 2? So that that InVar can be accessed in Tool 2? I want InVar to be user entered workspace (.gdb path) which will be used in Tool 2 to create a workspace. Eg. In tool 2 under "def getParameterInfo(self)" I want this: arcpy.env.workspace = InVar – Mony Sep 2 '15 at 23:33
  • Hi Mony, I have edited my original post to provide some further information. Hope this helps. – Ali Sep 3 '15 at 8:24

Create a script tool from which both Tool1 and Tool2 are executed.

You've stated you can create your two tools so just create a third tool which imports those script tools, takes the required parameter, passes it to script tool 1, then passes it to script tool 2.

The new script would only really require a few lines of code - import the toolbox, get the parameter, call tool 1, call tool 2

| improve this answer | |

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.