MCusumano

How to Properly Use env.scratchGDB to Gaurantee Write Access

Discussion created by MCusumano on Apr 29, 2013
Latest reply on Apr 29, 2013 by csny490
In scripting business processes it is coming up again and again where I need an intermediate workspace to write data. I am trying to copy a table to the scratch workspace but it is placing the table into a dbf in the folder where the scratchGDB is located. Here is what I have:

import arcpy, arceditor, logging, datetime, os, smtplib
from arcpy import env
arcpy.env.overwriteOutput = True
InputPrefix = "Database Connections\\Sun130 - 5151.sde\\"
tblImplsblRd = InputPrefix + "GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
lclImplsblRd = env.scratchGDB + "SAP_IMPLAUSIBLE_READS"

def copyRows(src, trgt, cfg):
    try:
        arcpy.CopyRows_management(src, trgt, cfg)
        logging.info(": Copied %s to %s" %(src, trgt))

    except Exception as e:
        print e
        logging.error(": %s" %(e))
        msgTxtErr = msgTxtErr + "\n" + "* " + str(e)
        errValue = 1

copyRows(tblImplsblRd, lclImplsblRd, "")

print "done"


When I run this from a script exported from ModelBuilder it places the table into the temporary gdb:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# temp.py
# Created on: 2013-04-29 10:29:12.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy


# Local variables:
GIS_INTERFACE_SAP_IMPLAUSIBLE_READS = "Database Connections\\Sun130 - 5151.sde\\GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
SAP_IMPLAUSIBLE_READS = "C:\\Users\\TDMC0\\AppData\\Local\\Temp\\scratch.gdb\\SAP_IMPLAUSIBLE_READS"

# Process: Copy Rows
arcpy.CopyRows_management(GIS_INTERFACE_SAP_IMPLAUSIBLE_READS, SAP_IMPLAUSIBLE_READS, "")



However if the path to the scratch GDB is hard-coded I will lose the ability to have a gauranteed space to write data. Would appreciate help getting this working correctly.

Outcomes