2

This tool I have designed is to create a buffer around Gas or Power lines then append the newly buffered data into the planning area. My custom tool's script is as follows:

# Import System Modules
import arcpy
import os

#Set Workspace
from arcpy import env
env.workspace = "C:/Code/Module7FProj"
arcpy.env.overwriteOutput = True

# Sets Parameters for Gas and Power line buffer for geoprocessing tool
GasPower_Lines_Buffer = arcpy.GetParameterAsText(0)
Output_GasPower_Buffer = arcpy.GetParameterAsText(1)
GasPower_Buffer_Distance = arcpy.GetParameterAsText(2)
Planning_Area = arcpy.GetParameterAsText(3)
Append_GasPower_Lines = arcpy.GetParameterAsText(4)


# create a 25 foot buffer from power and gas lines
arcpy.Buffer_analysis(GasPower_Lines_Buffer, Output_GasPower_Buffer,     GasPower_Buffer_Distance)

# append buffered power and gas lines with planning file
arcpy.Append_management(Output_GasPower_Buffer, Planning_Area,     Append_GasPower_Lines)

I need to create a separate script which imports this tool, sets the multiple inputs for "GasPower_Lines_Buffer" and sets the input for "Planning_Area".

So far I have:

import arcpy

arcpy.ImportToolbox("C:/Code/Module7FProj/FinalProj.tbx")
# below is where I need to set the parameters from the 
# previous script. Alias of toolbox is "FinalProjToolbx"
arcpy.FinalProjToolbx.FinalProj
1

I find the best way to learn something like this is to make ArcGIS do it first. You can do this by creating a model in ModelBuilder and adding your first script to it. Export that simple model to script (Model > Export > To Python Script...) - you don't need to make the model do everything.

The new exported script will include the reference to your toolbox and first script.

My exported result:

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("D:/temp/SE/tbtest/tb1.tbx")

# Process: My First Script
arcpy.myFirstScript_my_tb1()

The name of my script in the toolbox is myFirstScript, the name of my toolbox is tb1.tbx and the alias of my toolbox is my_tb1. For referencing the tool in arcpy you combine the script name and the alias with an underscore _, which gives me arcpy.myFirstScript_my_tb1().

This means your script would look something like this:

import arcpy

arcpy.ImportToolbox("C:/Code/Module7FProj/FinalProj.tbx")
# below is where I need to set the parameters from the 
# previous script. Alias of toolbox is "FinalProjToolbx"
arcpy.FinalProj_FinalProjToolbx()

Assuming FinalProj is the name of your first script, and FinalProjToolbox is the alias of your toolbox.

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.