Script geoprocessing dialog window help

3430
6
Jump to solution
04-14-2015 05:23 PM
MarkWisniewski
New Contributor III

In ArcGIS 10.3, I had my shapefile list working in the script geoprocessing dialog window for the projection tool;

# Get the spatial reference

spatialRef = arcpy.Describe(template).spatialReference.name

# Loop through shapfiles in folder and reproject

for fc in fcList:

  fcspatialRef = arcpy.Describe(fc).spatialReference.name

  if fcspatialRef != spatialRef:

   arcpy.Project_management(fc, outFolder + "\\" + fc, template)

# Print shapefile Project results

  arcpy.AddMessage(fc)

# Return any errors  

except:

arcpy.AddMessage(arcpy.GetMessages())

But when I add in copyFeatures_management because I want to copy the files which are already in the same projection and not reproject them, the dialog window changes and I lose my shapefile list in the geoprocessing dialog window;

# Get the spatial reference

spatialRef = arcpy.Describe(template).spatialReference.name

# Loop through shapfiles in folder and reproject

for fc in fcList:

  fcspatialRef = arcpy.Describe(fc).spatialReference.name

  if fcspatialRef != spatialRef:

   arcpy.Project_management(fc, outFolder + "\\" + fc, template)

  else:

   arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)

# Print shapefile Project results

arcpy.AddMessage(fc)

# Return any errors  

except:

arcpy.AddMessage(arcpy.GetMessages())

Can anyone please assist?

0 Kudos
1 Solution

Accepted Solutions
MarkWisniewski
New Contributor III

the solution is;

arcpy.AddMessage(fc)

arcpy.Project_management(fc, outFolder + "\\" + fc, template)

and not

arcpy.Project_management(fc, outFolder + "\\" + fc, template)

arcpy.AddMessage(fc)

View solution in original post

0 Kudos
6 Replies
SepheFox
Frequent Contributor

I'm not sure what you mean by "geoprocessing dialog window". Do you mean the results window? What exactly do you see?

0 Kudos
MarkWisniewski
New Contributor III

Yes Sephe, the results windows.

I used to see this;

Capture.JPG

And now I don't

0 Kudos
SepheFox
Frequent Contributor

Ah ok. Did the script perform the project and/or copy features? Well, anyway it's hard to tell from your formatting, but I think the script should be formatted like this:

for fc in fcList:

  fcspatialRef = arcpy.Describe(fc).spatialReference.name

  if fcspatialRef != spatialRef:

    arcpy.Project_management(fc, outFolder + "\\" + fc, template)

  else:

    arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)

Notice the if/else statements are indented under the for statement, and the commands are indented under those.

0 Kudos
MarkWisniewski
New Contributor III

Thanks Sephe, I couldn't work out why my script stopped working.

Ok, instead of printing out only the projected shapefiles (should be 6) in the list in the dialog window, it is printing both the projected and copied files (all 8 files).

0 Kudos
SepheFox
Frequent Contributor

Ok, try it like this:

# Loop through shapfiles in folder and reproject

for fc in fcList:

  fcspatialRef = arcpy.Describe(fc).spatialReference.name

  if fcspatialRef != spatialRef:

    arcpy.Project_management(fc, outFolder + "\\" + fc, template)

    # Print shapefile Project results

    arcpy.AddMessage(fc)

  else:

    arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)

0 Kudos
MarkWisniewski
New Contributor III

the solution is;

arcpy.AddMessage(fc)

arcpy.Project_management(fc, outFolder + "\\" + fc, template)

and not

arcpy.Project_management(fc, outFolder + "\\" + fc, template)

arcpy.AddMessage(fc)

0 Kudos