Replicate Model Builder XML formatted Report?

808
4
12-06-2010 10:10 AM
LynnHay
New Contributor
After running a model, you can MANUALLY generate a nice little XML report.  Is there any way to call that function from within Python since I schedule my py scripts to run off hours?

If not, what's the quick & dirtiest way to capture the output for review next day?

Thanks,

Lynn
Tags (2)
0 Kudos
4 Replies
StacyRendall1
Occasional Contributor III
Write all output to a text file at the end...

In your Python script have every message written to a master string, like so:
masterString = ''

# some geoprocessing on dataset
str_gp1_success = 'Completed GP1 on: %s' % dataset
arcpy.AddMessage(str_gp1_success)

masterString += '\n'+str_gp1_success # append the new string to the master, with a new line...


Do this kind of thing at every message, then at the end, save it to a plain text file (the file name and location can be an input parameter if you want):
outputFile = 'C:\\Temp\\output.txt'
w = open(outputFile,'w') # open file buffer - the second argument, w, tells it to open for writing
w.write(masterString)
w.close()


If you want to get fancy you can check for and delete the output file first, if it exists:
outputFile = 'C:\\Temp\\output.txt'
if os.path.exists(outputFile ): # write to file...
 os.remove(outputFile )
 print 'Deleted; %s' % outputFile
w = open(outputFile,'w') # open file buffer - the second argument, w, tells it to open for writing
w.write(masterString)
w.close()
0 Kudos
StacyRendall1
Occasional Contributor III
Oh, forgot to mention, you can do heaps of other fancy stuff if you can be bothered (so output is an XML, say), but it might not be worth the time...
0 Kudos
LynnHay
New Contributor
Stacy,
I appreciate those code snippets.  I'd even forgotten I posted this - that project is long past. I've built ArcObjects and JavaScript code for years with this type of message tracking, but left Python code to the automatically generated [verbose] scripts from Model Builder. PY will probably be fun and fairly familiar to learn.  It feels almost like "Back to the [AML] Future".

Moving to Arc10 will be my autumn project, and I've heard rumors about Python eclipsing VBA in versions to come.  Do you know if that's for ALL our custom tools (oh, no!!), or only geoprocessing tasks (YAY - Model Builder has saved my hide!) ? I saw your signature's website, so figured you're a good person to ask about this. I'm sort of a Lone Ranger here and taking code conversion into account will be necessary for scheduling my work.

I'd appreciate any insight you might have.

Thanks again,

Lynn
0 Kudos
StacyRendall1
Occasional Contributor III
Hi Lynn,

I'm not sure - you might be best to ask the ESRI guys! I think with 10 you can still make your own VB tools and import them as extensions (or something like that), but I'm not really sure what will be happening in the future (fortunately for me, all of my work has been in plain Model Builder or Python)...

Cheers,

Stacy
0 Kudos