ArcToolbox script will not return values

570
6
09-06-2011 01:16 AM
HenryColgate
Occasional Contributor
Okay most of that stuff in here before was redundant so it seems.

New toolbox, new Script.  No changes made to validation.  No input at all.  Just a straight run of the script does not work.

import arcpy
mxd = arcpy.mapping.MapDocument("current")
arcpy.AddMessage(mxd.title)

Hopefully that is a bit easier to answer cos I reckon I must be missing something really, really simple.
Tags (2)
0 Kudos
6 Replies
PhilMorefield
Occasional Contributor III
Okay most of that stuff in here before was redundant so it seems.

New toolbox, new Script.  No changes made to validation.  No input at all.  Just a straight run of the script does not work.

import arcpy
mxd = arcpy.mapping.MapDocument("current")
arcpy.AddMessage(mxd.title)

Hopefully that is a bit easier to answer cos I reckon I must be missing something really, really simple.


Based on what I see here, you are missing something really simple: a single line of code.

arcpy.GetMessages()
0 Kudos
KevinHibma
Esri Regular Contributor
Code is absolutely fine.
I suspect you dont have a title in your map document. If you dont have a title, mxd.title will equal ''.
In this case the AddMessage doesn't return anything.

The title it is returning is from:
File > Map Document Properties > Title: ________

Can you be sure you got something in there?
Also as a check, take your code into the Python window.
mxd = arcpy.mapping.MapDocument("current")
mxd.title

(the arcpy.AddMessage isn't going to do what you want in the Py Window
0 Kudos
PhilMorefield
Occasional Contributor III
Code is absolutely fine.
I suspect you dont have a title in your map document. If you dont have a title, mxd.title will equal ''.
In this case the AddMessage doesn't return anything.

The title it is returning is from:
File > Map Document Properties > Title: ________

Can you be sure you got something in there?
Also as a check, take your code into the Python window.
mxd = arcpy.mapping.MapDocument("current")
mxd.title

(the arcpy.AddMessage isn't going to do what you want in the Py Window


Based on my reading of his description, it looks like he's trying to run this as a script tool, not from the Python window. Hence, he would need arcpy.GetMessages() to return the document title to the geoprocessing window.
0 Kudos
HenryColgate
Occasional Contributor
Yes, just needed to add the info there in File... Map Docuemnt Properties... Title

I thought it was getting pulled straight from the file name.

Thanks.
0 Kudos
KevinHibma
Esri Regular Contributor
Based on my reading of his description, it looks like he's trying to run this as a script tool, not from the Python window. Hence, he would need arcpy.GetMessages() to return the document title to the geoprocessing window.


arcpy.GetMessages is specific to getting messages from a tool which has executed.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/GetMessages/000v0000000p000000/
0 Kudos
PhilMorefield
Occasional Contributor III
arcpy.GetMessages is specific to getting messages from a tool which has executed.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/GetMessages/000v0000000p000000/


Well, this is a digression, but that link is a bit misleading. You can put whatever you want into a message. For example, if you put this code into a script tool:

import arcpy
arcpy.AddMessage("This is just a message...")
arcpy.AddWarning("This text is green...")
arcpy.AddError("This text is red...")
arcpy.GetMessages()

# this will make the tool bomb out
foo = bar


No tools have executed but you've still returned three messages.
0 Kudos