Python - help with GetMessage

3987
5
Jump to solution
04-15-2015 02:08 AM
MarkWisniewski
New Contributor III

Hi,

I am after a way on using arcpy.GetMessage to achieve the following message in the geoprocessing dialog result window?;

The above 4 datasets have been reprojected to: WGS Web Mercator (auxiliary sphere) and saved in S:\GisData

Does anybody know this can be achieved?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

Ernst Kemmerer wrote:

I cant get it to work.

That's not very informative. What does "cant get it to work" mean exactly? Do you get an unexpected result, do you get an error message, does python crash, does your PC crash, does your PC spontaneously combust and let all the magic smoke out?

Just kidding, what was the error message/unexpected result?

PS: you are setting  projCount to the number of features in the last fc that you reproject. If you want to print the number of fcs that you reprojected, you need to do something like:

projCount = 0
for fc in fcList:

    etc...
    if fcspatialRef != spatialRef:

        arcpy.Project_management(fc, outFolder + "\\" + fc,template)
        projCount += 1 #or projCount = projCount + 1

View solution in original post

0 Kudos
5 Replies
Luke_Pinner
MVP Regular Contributor

Do you mean arcpy.AddMessage('some message... ')?

0 Kudos
DanPatterson_Retired
MVP Emeritus

GetMessages documentation....for recording errors

GetMessage documentation ... for geoprocessing services if there are any messages

Within there are a bunch of other message types.

AddMessage is needed to add 'stuff' which can be retrieved by any of the 'Gets...

0 Kudos
MarkWisniewski
New Contributor III

Trying to do this, which I cant get arcpy.Message(fc) and arcpy.Message(msg) to display results in dialog window.

#Loop through shapfiles in folder and reproject
 for fc in fcList:
  fcspatialRef = arcpy.Describe(fc).spatialReference.name
   if fcspatialRef != spatialRef:
  arcpy.Project_management(fc, outFolder + "\\" + fc, template)
  projCount = int(arcpy.GetCount_management(fc).getOutput(0))
   else:
  arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)

# Print shapefile Project results
  arcpy.AddMessage(fc)
# Get the count from GetCount's Result object
 msg = "{0} datasets have been reprojected to: {1} and saved in {2}".format(projCount, spatialRef, OutFolder)
 arcpy.AddMessage(msg)
0 Kudos
Luke_Pinner
MVP Regular Contributor

Ernst Kemmerer wrote:

I cant get it to work.

That's not very informative. What does "cant get it to work" mean exactly? Do you get an unexpected result, do you get an error message, does python crash, does your PC crash, does your PC spontaneously combust and let all the magic smoke out?

Just kidding, what was the error message/unexpected result?

PS: you are setting  projCount to the number of features in the last fc that you reproject. If you want to print the number of fcs that you reprojected, you need to do something like:

projCount = 0
for fc in fcList:

    etc...
    if fcspatialRef != spatialRef:

        arcpy.Project_management(fc, outFolder + "\\" + fc,template)
        projCount += 1 #or projCount = projCount + 1
0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Hi Ernst, besides including the actual error message in your reply as Luke suggested, it would help if you put you code in a formatted code block for Python, like is shown in Luke's reply.  Python is very picky on the indentation, and a straight copy/past tends to mess is up, making it hard for others to know whether indentation is causing you an issue or if there is some other issue.  there is a good how-to Posting Code blocks in the new GeoNet​   It's a very quick read, and since you seem to be getting into Python quick a bit this past week, it's worth getting in the habit since it would help others help you.  Main things, you have to be responding from the thread, not from within your inbox, so you can see the "Use Advanced Editor".   Good luck, and I hope you get you problem resolved.

0 Kudos