Hi,
I am trying to create a tool using model builder in Arcmap 10.4 which will allow the user to draw a polygon interactively and clip all layers within the polygon. The clipped layers will then be saved in an output file geodatabase containing a featuredataset having same name as the original layers. My input layers are from a file geodatabase containing featuredataset. My idea is to add the output to a new map document automatically or replace the existing TOC. I am attaching my tool, input and output file geodatabase. I will appreciate any kind of help regarding the Problem.
Regards,
Rimon
This requires a little Python scripting using the Calculate Value tool. You need to write a function (placed in the Calculate Value code block) that opens a template MXD and sets all the new paths using the arcpy.mapping module. The inputs to the function would be the template MXD (this could be a model element) and the path to your output gdb. The calculate value expression would be something like:
save_mxd(r"%mxd_template%", r"%output_mxd_folder%", r"%output_gdb%")
Hi,
Thanks for your reply. I am new to python. I tried to evaluate the expression above as you stated within the calculate value. But it takes save_mxd as a variable I think and It gives error result. Can you look at it and see what is the problem? Thanks in advance.
you have nothing in the expression box you need to make it a function and usewhat Curtis supplied should go in the code box. your line should go in the expression box to call the function which is names save_mxd
Calculate Value—Tools | ArcGIS Desktop look at the provided image from the help
Hi Dan!
Thanks a lot for your reply. I tried to make a function in calculate value tool but did not succeed. Instead if I try to elaborate and create a script in python that will take a geodatabase/featuredataset as input and place the featuredataset in TOC of a new mapdocument. My intension is to use the same dataframe from the current map document. My Idea is like this,
# Import module
import os
import arcpy
from arcpy import env
# Set input parameter (I want to connect this script to the model output which is a geodatabase and param0 will take the .gdb as input)
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName="Input Geodata",
name="in_workspace",
datatype="DEGeodatasetType",
parameterType="Required",
direction="Input")
return param0
# Set environment
arcpy.env.workspace = ("param0")
mxd = arcpy.mapping.MapDocument("CURRENT")
# Copy the dataframe from current mxd to a new mxd and add the inputted gdb to map document.
for df in arcpy.mapping.ListDataFrames(mxd):
for ds in arcpy.mapping.ListDataset(feature_type='feature')
for fc in arcpy.mapping.ListFeatureClasses()
mxd.saveACopy(r"C:\Users\attrab01\Downloads\PK\\" + "Project"+ ".mxd")
del mxd1
# Open the new mxd automatic
os.startfile(r"C:\Users\attrab01\Downloads\PK\\" + "Project" + ".mxd")
This is a very basic and logical structure of my desired output. I would really appreciate if you can give me an exaple how to compile the code in python. Thanks in advance.
To get the code into a readable format first. Your code should be using parameters rather than hard coded, like your references to the folder location. You can make a script tool for use in ArcToolbox possibly, or simply use a python IDE to run the script. I am guessing that you did neither or you would have reported error message or it would have worked