ArcPy - How do I run custom script tools within the console?

3666
6
Jump to solution
01-12-2018 07:53 AM
MarcusSanders2
New Contributor II

For example, I have a custom tool "wellTabletoFC". When I pull up the Item Description, it gives me a syntax as if it can be used within the console:

wellTabletoFC(Input_Table)

When I drag the script into the Python window, I get this code:

>>> arcpy.wellTabletoFC()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'wellTabletoFC'‍‍‍‍‍

How do I use my own tools in the same way as ArcGIS tools within ArcPy, for example:

arcpy.Project_management(
    in_dataset,
    out_dataset,
    out_coor_system,
    transform_method,
    {in_coor_system},
    {preserve_shape},
    {max_deviation},
    {vertical}
    )

I want to do this for 2 reasons:

  1. Run the tool within the Python console, while being able to return the tool output into a variable,
  2. Chain multiple custom tools together that are maintained separately, into a single workflow
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JonathanQuinn
Esri Notable Contributor

If it's a script tool in a toolbox, you can import the toolbox and script tool:

Adding toolboxes in Python—Geoprocessing and Python | ArcGIS Desktop 

View solution in original post

6 Replies
DanPatterson_Retired
MVP Emeritus

is it a script? (aka module) in a location that is within your import path?

import wellTabletoFC
0 Kudos
JonathanQuinn
Esri Notable Contributor

If it's a script tool in a toolbox, you can import the toolbox and script tool:

Adding toolboxes in Python—Geoprocessing and Python | ArcGIS Desktop 

MarcusSanders2
New Contributor II

Just what I was looking for, works perfectly! Thank you

0 Kudos
MarcusSanders2
New Contributor II

This doesn't seem to persist after ArcMap is closed; is this something that only works during that session?

0 Kudos
JonathanQuinn
Esri Notable Contributor

Yes, every time you run your script you need to import the toolbox, much like you need to import any modules at runtime as well.

MarcusSanders2
New Contributor II

That makes sense, thank you

0 Kudos