Select to view content in your preferred language

Export Selected Features from Layer within ArcMap

7551
13
10-19-2015 11:18 AM
mpboyle
Frequent Contributor

I'm trying to create a python script that will export selected features from a layer within ArcMap.  The general workflow would be the following:

1) User opens ArcMap

2) User manually selects features from layer

3) User runs script that exports ONLY selected features from layer

This seems pretty straight-forward but I'm not used to dealing with interactive selections.  I'm also wondering if it's necessary to add in some logic for variances in layer names since users may alter the layer name...?  Can this be made as a parameter of the script?

I'm also wondering if it would be best to have users run this as a python tool from a toolbox or if a python add-in is possible so it's a button click...?

0 Kudos
13 Replies
LukeSturtevant
Frequent Contributor

Matthew, the GetParameterAsText ​is for setting parameters for a script tool. In my code there are two parameters that the script tool would look for then. An Input Layer and an Output Layer. Also I need to edit the code because the first input should be arcpy.GetParameterAsText(0).

If you want to test the code outside of a python script tool you would set the 'lyr' to a full path to a shapefile or feature class. Such as: lyr = "C:\Test.shp"

mpboyle
Frequent Contributor

I appreciate your help!  Sorry for all the questions, first time I've really worked with GetParameter and python script tools. Now that I understand what it's used for and how to test it properly, this makes sense

I can then use the Parameters toolbar to index the parameters, is that right?

0 Kudos
LukeSturtevant
Frequent Contributor

You got it. You can set the output parameter to be a Feature Layer and then direction to Output like so.

SibghatUllah1
Regular Contributor
0 Kudos