fullmetalzinc

Trying to modify Batch Project to Output to a mirrored path tree

Discussion created by fullmetalzinc on Jun 1, 2012
Latest reply on Jun 1, 2012 by nahmed-esristaff
Hi there, 

I am attempting to modify the Batch Project script to:
[INDENT]a) read from a text file of file names located on our server
b) build a mirror of the paths to those files on my local machine
c) output to my local machine at the end of those paths. The paths should also be appended to a user specified location
[/INDENT]
My code works to an extent, but stops after the first projection, as per:

[INDENT]Projected S:\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_PanCon.shp to C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp successfully.

Failed to project S:\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_Rocks.shp. Failed to execute. Parameters are not valid.
ERROR 000725: Output Dataset or Feature Class: Dataset C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp already exists.
Failed to execute (Project).

Failed to project S:\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_Silts.shp. Failed to execute. Parameters are not valid.
ERROR 000725: Output Dataset or Feature Class: Dataset C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM\_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp already exists.
Failed to execute (Project).[/INDENT]

Here is my code:

#Import required modules
import ConversionUtils, time, sys, os, arcpy
 
#Define message constants so they may be translated easily
msgWorkspace = ConversionUtils.gp.GetIDMessage(86109) # Message "Output workspace does not exist: "
msgCoordinateSystem = ConversionUtils.gp.GetIDMessage(86110)  #Message "Must Enter a Spatial Reference or Template Feature Class."
msgFail = ConversionUtils.gp.GetIDMessage(86111) # Message "Failed to project "
 
#Set the input datasets
inputs = [item.replace('\n', '') for item in open(sys.argv[1]).readlines()]  
 
 
for line in inputs:
    line = line.replace("\\\\", "\\")#changing slashes to single slashes
    
#print the stripped line
    (drive, path) = os.path.splitdrive(line)
    arcpy.AddMessage("path before the join is " + path)
    print "path before the join is " + path
    arcpy.AddMessage(" ConversionUtils.gp.GetParameterAsText(1) before the join is " + ConversionUtils.gp.GetParameterAsText(1))
    outdata=os.path.normpath(ConversionUtils.gp.GetParameterAsText(1)+path)
    arcpy.AddMessage(" ConversionUtils.gp.GetParameterAsText(1) after the join is " + ConversionUtils.gp.GetParameterAsText(1))
    arcpy.AddMessage("path after join is " + path)
#    print "outdata is " + outdata
#    print "path after join is " + path
    arcpy.AddMessage("outdata is " + outdata)
    try:
        (path2,fileName) = os.path.split(outdata)
        os.makedirs(path2)
    except OSError:
        print "Skipping creation of the following path because it exists already: " + path2
        #if path exists, this will be printed
        arcpy.AddMessage("Skipping creation of the following path because it exists already: " + path2)
    
    #print line.strip()
 
output_workspace = ConversionUtils.gp.GetParameterAsText(2)    
#Set the spatial reference
output_coordinate_system = ConversionUtils.gp.GetParameterAsText(3)
 
#Set the template dataset
template_dataset = ConversionUtils.gp.GetParameterAsText(4)
        
#Set the transformation
transformation = ConversionUtils.gp.GetParameterAsText(5)
#Message 86112   "Projecting multiple datasets ..."
ConversionUtils.gp.SetProgressor("step", ConversionUtils.gp.GetIDMessage(86112), 0, len(inputs))
 
if (output_coordinate_system == "" or output_coordinate_system == "#") and (template_dataset == "" or template_dataset == "#"):
    raise ConversionUtils.GPError(msgCoordinateSystem) 
elif (output_coordinate_system != "") and (output_coordinate_system != "#"):
    sr = output_coordinate_system
elif (template_dataset != "") and (template_dataset != "#"):
    dsc = ConversionUtils.gp.Describe(template_dataset)
    sr = dsc.SpatialReference
 
for input in inputs:
    try:
        #outdata = ConversionUtils.GenerateOutputName(input, output_workspace)
                #Message 86113 "Projecting "
        ConversionUtils.gp.SetProgressorLabel(ConversionUtils.gp.GetIDMessage(86113) + input)        
        ConversionUtils.gp.Project_management(input, outdata, sr, transformation)
        print outdata
        arcpy.AddMessage(outdata) 
        #Message 86114 "Projected %s to %s successfully."
        ConversionUtils.gp.AddMessage(ConversionUtils.gp.GetIDMessage(86114) % (input, outdata))
        
    except Exception, ErrorDesc:
        msgWarning = msgFail + "%s" % input
        msgStr = ConversionUtils.gp.GetMessages(2)
        ConversionUtils.gp.AddWarning(ConversionUtils.ExceptionMessages(msgWarning, msgStr, ErrorDesc))
        
    ConversionUtils.gp.SetProgressorPosition()
 
time.sleep(0.5)


Any help would be appreciated

Outcomes