0

I would like each function to be added into the opened mxd. This was originally designed to run in Catalog, but the users will all be using ArcMap.

This is my Script:

# nrcs_script_main.py
# Description: This Script will serve to create a geodatabase, create Area of Interest Raster Datasets, and process them with external functions
# Parameters (type): folder_for_gdb (folder), file_gdb_name (string), dem (raster dataset), input_mask_polygon (shapefile), contour_interval (double), smoothing_distance (linear unit)
# ---------------------------------------------------------------------------
# Set the necessary product code
import arceditor
# Import arcpy module
import arcpy
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Import tool modules
import sys
import os
import shutil
import aoigen
import useraoigen
import contourgen
import hydrology
# Script arguments
project_folder = arcpy.GetParameterAsText(0)
folder_for_gdb = project_folder + "\\" + arcpy.GetParameterAsText(1)
file_gdb_name = arcpy.GetParameterAsText(1)
dem = arcpy.GetParameterAsText(2)
dem_sr = arcpy.GetParameterAsText(3)
extraction_checkbox = arcpy.GetParameterAsText(4)
input_mask_polygon = arcpy.GetParameterAsText(5)
mask_polygon_sr = arcpy.GetParameterAsText(6)
aoi_buffer_dist = arcpy.GetParameterAsText(7)
contour_checkbox = arcpy.GetParameterAsText(8)
contour_interval = arcpy.GetParameterAsText(9)
if contour_interval == '#' or not contour_interval:
 contour_interval = "1" # provide a default value if unspecified
smoothing_distance = arcpy.GetParameterAsText(10)
contour_thinning = arcpy.GetParameterAsText(11)
import_rule_layer = arcpy.GetParameterAsText(12)
contour_unit_conversion_factor = arcpy.GetParameterAsText(13)
hydrology_checkbox = arcpy.GetParameterAsText(14)
# Copy and Paste job folder
arcpy.AddMessage("Copy and Paste Folder")
src = os.path.join("C:\\",'ArcPy_NRCS','Template')
dst = folder_for_gdb
shutil.copytree(src,dst,symlinks=False,ignore=None)
# Rename Map Document
arcpy.AddMessage("Rename directories and Documents")
os.rename(dst + '\\template.mxd', dst + '\\' + file_gdb_name + '.mxd')
# Execute Selected Functions
if extraction_checkbox == "true":
 arcpy.AddMessage("Aoigen.aoi")
 aoigen.aoi(folder_for_gdb, file_gdb_name, dem, input_mask_polygon,aoi_buffer_dist)
 if contour_checkbox == "true":
 arcpy.AddMessage("Running Contouring Functions")
 contourgen.contour(folder_for_gdb, file_gdb_name, contour_interval, smoothing_distance, contour_thinning, import_rule_layer, contour_unit_conversion_factor)
 if hydrology_checkbox == "true":
 arcpy.AddMessage("Running Hydrology Functions")
 aoi = folder_for_gdb +"\\" + "Project_Datasets.gdb" + "\\" + "AOI_dem"
 hydrology.drainvis(folder_for_gdb,file_gdb_name,aoi) 
else:
 arcpy.AddMessage("useraoigen.useraoi")
 useraoigen.useraoi(folder_for_gdb, file_gdb_name, dem)
 if contour_checkbox == "true":
 arcpy.AddMessage("Running Contouring Functions")
 contourgen.contour(folder_for_gdb, file_gdb_name, contour_interval, smoothing_distance, contour_thinning, import_rule_layer,contour_unit_conversion_factor)
 if hydrology_checkbox == "true":
 arcpy.AddMessage("Running Hydrology Functions")
 aoi = folder_for_gdb +"\\" + "Project_Datasets.gdb" + "\\" + "AOI_dem"
 hydrology.drainvis(folder_for_gdb,file_gdb_name,aoi) 
# Add Map in ArcGIS
mapdoc = os.path.join(folder_for_gdb,file_gdb_name+".mxd")
arcpy.AddMessage("Lidar Toolset Finished! Your Map document will open when this window is closed.") 
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 31, 2015 at 12:27

1 Answer 1

2

I am not an ArcGIS user, but the following links may contain information and tips on how to add layers to your TOC:

answered Mar 31, 2015 at 13:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.