Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.Union_analysis(.....

arcpy.Clip_analysis(.....

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

share|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. –  Dan Patterson 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 –  Dan Patterson Jun 29 '11 at 14:11
    
Thx for now. How could use the parameter to writing points? –  zippy Jun 29 '11 at 14:37
show 2 more comments

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

share|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
add comment

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.

share|improve this answer
    
See also the help topic on writing geometries help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/… which shows how to use InsertCursors once you have created your feature class. This approach works with all ArcMap license levels –  Dan Patterson Jun 30 '11 at 12:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.