I created a python script for a toolbox and I am wondering about the fact that CreateFeatureclass_management doesn't add the feature-class as layer in the actual dataframe. This does not happen in the environment of a toolbox, but if I create a feature-class in the python window of ArcMap it creates the wanted layer.

I already tried MakeFeatureLayer_management followed by AddLayer, with no result.

What I am doing wrong?


Is the feature layer you are creating a parameter for your tool? If not, then the results of are not added to the display. Consider the following workflow (simplified to demonstrate). In this example there are a variety of shapefiles created from a union, a clip, then a conversion of multipart to single part shapes. The only file that is added to the display in ArcMap is the file specified as a tool parameter (in this case out_FC) and none of the intermediate ones were even though the reside on disk.



arcpy.MultipartToSinglepart_management(clip_FC, out_FC) #final output file

So if you want results to be automatically added to ArcMap during a workflow, then do as PolyGeo says, but specify them as parameters in the tool.

EDIT As an example, here is a toobox that I am working on that has one input parameter and one output parameter, however, there are 4 other shapefiles created along the way, none of which get added to the display...only the output parameter (in this case a shapefile).

Sample parameter list

| improve this answer | |
  • My script creates a feature-class of type point for points out of a simple textfile. The file to the textfile is the only once parameter of the toolbox. I create the feature-class as shp in a folder that is not witin the workspace. – zippy Jun 29 '11 at 12:12
  • The input textfile is an input parameter. The output shapefile should be specified as an output parameter in the tool. If it is specified as an output parameter, it will be added to the display. If you don't specify it as an output parameter, it will be created but NOT added to ArcMap's display. – user681 Jun 29 '11 at 13:32
  • What type of parameter it should be? – zippy Jun 29 '11 at 13:48
  • Direction is Output Type should be a Shapefile if you are creating a shapefile. See the image in my original post – user681 Jun 29 '11 at 14:11
  • Thx for now. How could use the parameter to writing points? – zippy Jun 29 '11 at 14:37

I think you may need to check Add results of geoprocessing operations to the display in the Geoprocessing > Geoprocessing Options.

For more info see http://help.arcgis.com/en/arcgisdesktop/10.0/help/0021/00210000000q000000.htm

| improve this answer | |
  • It does not work with the checked option. – zippy Jun 29 '11 at 11:55
  • It's late here now so I will try to test tomorrow – PolyGeo Jun 29 '11 at 11:58

When you use arcpy.CreateFeatureclass_management, it just creates an empty featureclass. What you then need to do, is add data to it.

So, you could use this:

arcpy.CreateFeatureclass_management(path, name, "POLYGON", "", "", "", "", "", 100, 0, 0)

then put something into it like:

arcpy.AggregatePoints_cartography(polyGeometryList, path + name, "1000 meters")

This would add a list of points aggregated into a polygon, into your created featureclass.

Hopefully this makes sense, but when you use createFC_Management, you're essentially creating an empty shell.

| improve this answer | |

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.