<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Century Gothic";
        panose-1:2 11 5 2 2 2 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>Jim,
<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>In
Python 2.5 under ArcMap 9.3 domains can be only listed. To get to the domain
values, they need to be converted to tables. Also, the default value cannot be
obtained from the existing GP API. Very annoying! The workaround is to use VBA
ArcObjects or connect to the database directly, if possible, and extract the
information from the GDB. This latter will work for PGDB, not sure about FGDB.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>Regards,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Valentina Boycheva<br>
<br>
</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal style='margin-left:.5in'><b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> Jim Valenza [mailto:jim.valenza@gmail.com] <br>
<b>Sent:</b> Tuesday, November 10, 2009 2:33 PM<br>
<b>To:</b> python-list@python.org<br>
<b>Subject:</b> New to Python need on advice on this script<o:p></o:p></span></p>

</div>

<p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p>

<div>

<p class=MsoNormal style='margin-left:.5in'>Hello all - I'm new to the world of
Python as I am a GIS guy who would like to broaden his horizons. I have a
question about a script that we've been working on: The purpose of the
code is to <strong><span style='font-size:10.0pt;font-family:"Century Gothic","sans-serif";
color:black'>Syncronize SDE DropBox with Regulatory Project working files. </span></strong><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'> <o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'>I am looking for where the
script dumps the domain list to a table and loops through the table? Is It
necessary? Seems like you should be able to simply loop through the domain
list. I was just trying to see if there was a more straitforward way. Thanks<o:p></o:p></p>

</div>

<p style='margin-left:.5in'>The script is as follows:<o:p></o:p></p>

<div>

<p class=MsoNormal style='margin-left:.5in'> <o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'># Create the
Geoprocessor<br>
import sys, string, os, arcgisscripting, shutil, time<br>
gp = arcgisscripting.create()</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'># Jim V testing<br>
# Allow output to overwrite<br>
gp.OverwriteOutput = 1</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>gp.AddToolbox("C://Program
Files//ArcGIS//ArcToolbox//Toolboxes//Data Management Tools.tbx")</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>#---create a logging
file named "YYYYMMDD HH_MM_QualityControlLog.txt" <br>
theTime = time.strftime('%Y%m%d %H_%M')<br>
#logfilename = "H:\\Development\\Python\\" + theTime +
"_PODsQAQCLog.txt"<br>
logfilename =
"L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\"
+ theTime + "_PODsQAQCLog.txt"<br>
log = open(logfilename,'w')<br>
log.write(time.ctime() + "\n")<br>
print time.ctime()</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>THE_WORKSPACE =
os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin")
+ "\\"  #REAL MODE LINE<br>
#THE_WORKSPACE = os.path.normpath("H:/Development/testdata") +
"\\"  #TEST MODE LINE<br>
log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n")<br>
print "THE_WORKSPACE IS " + THE_WORKSPACE</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>P_CODE =
"P_CODE"</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>#Create table of valid
P_CODEs and convert to List<br>
gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb",
\<br>
                           
"regulatory_p_code",
r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table",
\<br>
                           
"pcode", "pdesc", "")<br>
#searchRows =
gp.searchCursor(r"H:\Development\temp\test.mdb\code_table")<br>
searchRows =
gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table")<br>
searchRow = searchRows.next()<br>
domainList = []<br>
while searchRow:<br>
    domainList.append(searchRow.pcode)<br>
    searchRow = searchRows.next()<br>
#print domainList</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>try:</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>    #Get
Workspaces from text file<br>
    #for line in
open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'):  
#REAL MODE LINE<br>
    for line in
open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QAQC_Scripts/PRB_POD_Paths.txt",
'r'):   #REAL MODE LINE<br>
    #for line in
open("H:/Development/testdata/workspaces.txt",
'r'):    #TEST MODE LINE<br>
        if not line: break<br>
        line = line.strip()<br>
        if not
line.startswith("#"): # skip lines that start with #<br>
            ws, P =
line.split("RMP_2_5_",1) #parse line to get path and P_CODE<br>
           
log.write("  " + "\n")<br>
           
log.write("  " + "\n")<br>
            log.write(P
+ "\n")<br>
            print
"  "<br>
            print P<br>
            src =
THE_WORKSPACE + line  #defines each workspace path<br>
            <br>
            #If the
Geodatabase exists, perform the operations<br>
            if
os.path.exists(src):<br>
               
#Archive Geodatabase before running script<br>
               
log.write("The Geodatabase exists " + src + "\n")<br>
               
print "The Geodatabase exists " + src<br>
               
archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" +
"RMP_2_5_" + P<br>
               
log.write("archiveFolder is " + archiveFolder + "\n")<br>
               
print "archiveFolder is " + archiveFolder<br>
               
shutil.copy(src, archiveFolder)    #Archive the Geodatabase</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>               
#Set workspace and variables<br>
               
gp.workspace = src<br>
               
log.write(gp.workspace + "\n")<br>
               
print gp.workspace<br>
               
P_Value = (P.strip(".mdb"))</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>               
#Valitate P_Code value against Domain list<br>
               
if P_Value in domainList:<br>
                   
log.write("P_Code is valid:  " + P_Value + "\n")<br>
                   
print "P_Code is valid:  " + P_Value</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>                   
# List all feature classes in feature datasets<br>
                   
fdss = gp.ListDatasets("","")<br>
                   
fds = fdss.Next()<br>
                   
while fds:<br>
                       
fcs = gp.ListFeatureClasses("*","",fds)<br>
                       
fc = fcs.Next()<br>
                       
while fc:<br>
                           
gp.CalculateField_management(fc, P_CODE, "'" + P_Value +
"'", "PYTHON")    #Calc P_Code<br>
                           
gp.RepairGeometry(fc,
r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\outy.shp")<br>
                           
fc = fcs.Next()<br>
                           
print fc<br>
                       
fds = fdss.Next()</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>                   
#Copy the Geodatabase to the SDE InBox<br>
                   
sdeInbox = "S:/Production/DropBox/InBox"   #REAL MODE LINE<br>
                   
#sdeInbox = "H:/Development/testInbox"   #TEST MODE LINE<br>
                   
log.write("sdeInbox is " + sdeInbox + "\n")<br>
                   
print "sdeInbox is " + sdeInbox<br>
                   
shutil.copy(src, sdeInbox)     #Copy Geodatabase to SDE
Inbox<br>
               
else:<br>
                   
log.write("P_Code is NOT valid:  " + P_Value + "\n")<br>
                   
print "P_Code is NOT valid:  " + P_Value<br>
            else:<br>
               
log.write("The Geodatabase does not exist " + src + "\n")<br>
               
print "The Geodatabase does not exist " + src</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>except:<br>
    # If an error occurred, print the messages returned by the
tool<br>
    log.write(gp.GetMessages() + "\n")<br>
    print gp.GetMessages()</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
font-family:"Century Gothic","sans-serif";color:black'>log.write(time.ctime() +
"\n")<br>
log.write("FINISHED" + "\n")<br>
os.startfile("L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\")<br>
log.close()<br>
print "FINISHED"<br>
print time.ctime()</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'> <o:p></o:p></p>

</div>

</div>

</body>

</html>