Scratch GDB being treated as folder instead of FGDB in script

1126
1
Jump to solution
05-31-2018 06:34 AM
MKF62
by
Occasional Contributor III

I am writing output data to the scratch geodatabase in a script - it was working great before but now it is no longer working and I'm trying to figure out if it's an IDE problem or something else. When I write data to the scratch geodatabase, it is treating it as a folder and appending ".shp" to the end of the output data instead of treating it as a file geodatabase and writing the output data as a feature class like it's supposed to. Additionally, it will run through the first tool call and write the output, but then the second tool call results in an error because it's trying to append ".shp.shp" to the output data name which is obviously invalid... I'm leaning towards this being an IDE problem because the script works great if I add the toolbox to ArcMap and run it inside there. Has anybody else seen this fishy behavior using PyCharm? 

The problem script:

scratchGDB = arcpy.env.scratchGDB

#First tool call appends .shp to singlepart
#output looks like this: C:\Users\xxx\AppData\Local\Temp\scratch.gdb\singlepart.shp
svyPtFC = arcpy.MultipartToSinglepart_management(multipartFL, os.path.join(scratchGDB, 'singlepart'))

#Second tool call tries to append .shp.shp to FinalOutput
#Error says: ExecuteError: ERROR 000210: Cannot create output 
#C:\Users\xxx\AppData\Local\Temp\scratch.gdb\FinalOutput.shp.shp
#ERROR 000354: The name contains invalid characters
filename = os.path.join(scratchGDB, "FinalOutput")
svyPtFC = arcpy.Eliminate_management(sliverFL, filename)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It truly does write the shapefile out into the geodatabase folder:

If I run this code to check if it's a geodatabase I get this:

scratchGDB = arcpy.env.scratchGDB

desc = arcpy.Describe(scratchGDB)
print desc.workspaceType

#Prints "FileSystem"‍‍‍‍‍‍

How do I get it to be seen as a file geodatabase when running in an IDE?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Occasional Contributor III

Well I fixed it. I had to set the scratchWorkspace first. No idea why it was working before without setting that, but it no longer likes to have the scratch.gdb sitting in AppData\Local\Temp. 

Kinda stinks that I have to do this though because I'll need to remember to comment the scratchWorkspace line out when I publish it as a geoprocessing service since the GP service should use the jobs folder as it's workspace, thus the directory of the scratchWorkspace will never be the same and should not be set.

Fixed code:

arcpy.env.scratchWorkspace = r'C:\Users\xxx\Desktop\GIS_Testing'
scratchGDB = arcpy.env.scratchGDB

#scratchGDB now resides at C:\Users\xxx\Desktop\GIS_Testing\scratch.gdb‍‍‍‍

View solution in original post

1 Reply
MKF62
by
Occasional Contributor III

Well I fixed it. I had to set the scratchWorkspace first. No idea why it was working before without setting that, but it no longer likes to have the scratch.gdb sitting in AppData\Local\Temp. 

Kinda stinks that I have to do this though because I'll need to remember to comment the scratchWorkspace line out when I publish it as a geoprocessing service since the GP service should use the jobs folder as it's workspace, thus the directory of the scratchWorkspace will never be the same and should not be set.

Fixed code:

arcpy.env.scratchWorkspace = r'C:\Users\xxx\Desktop\GIS_Testing'
scratchGDB = arcpy.env.scratchGDB

#scratchGDB now resides at C:\Users\xxx\Desktop\GIS_Testing\scratch.gdb‍‍‍‍