Python - How to customise result in geoprocessing dialog window

3781
8
Jump to solution
04-12-2015 10:44 PM
MarkWisniewski
New Contributor III

This is my python script code in ArcGIS 10.3;

projectResult = arcpy.Project_management(fc, outFolder + "\\" + fc, template) 
# Name of shapefiles re-projected in result dialog window        
arcpy.AddMessage(projectResult)

Which gives me this in the geoprocessing dialog result box;

C:\GIS_Result\abc.shp 
C:\GIS_Result\1234.shp 
C:\GIS_Result\zyx.shp 
C:\GIS_Result\987.shp

Can I remove the filepath to give me just the filename?;

abc.shp
1234.shp
zyx.shp
987.shp

0 Kudos
1 Solution

Accepted Solutions
KishorGhatage
Occasional Contributor III

Try using:

arcpy.AddMessage(fc)

or

arcpy.AddMessage(projectResult.replace("C:\GIS_Result\","")

I am not python expert. Hope this is helpful

Kishor

View solution in original post

0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus

try a variant of this

>>> projectResult = [r'C:\GIS_Result\abc.shp',r'C:\GIS_Result\1234.shp',r'C:\GIS_Result\zyx.shp']
>>> msg = [out.split('\\')[-1] for out in projectResult]
>>> msg
['abc.shp', '1234.shp', 'zyx.shp']
>>>
KishorGhatage
Occasional Contributor III

Try using:

arcpy.AddMessage(fc)

or

arcpy.AddMessage(projectResult.replace("C:\GIS_Result\","")

I am not python expert. Hope this is helpful

Kishor

0 Kudos
DanPatterson_Retired
MVP Emeritus

not sure that is what he wants...

>>> for i in projectResult:
...  i.replace("C:\\GIS_Result\\","")
...
'abc.shp'
'1234.shp'
'zyx.shp'
>>> projectResult
['C:\\GIS_Result\\abc.shp', 'C:\\GIS_Result\\1234.shp', 'C:\\GIS_Result\\zyx.shp']
>>>

it doesn't seem to change the list

and with this, I get an error message since projectResult is a list

>>> projectResult.replace("C:\GIS_Result\","")
Traceback (  File "<interactive input>", line 1
    projectResult.replace("C:\GIS_Result\","")
                                             ^
SyntaxError: EOL while scanning string literal
>>>
0 Kudos
MarkWisniewski
New Contributor III

Kishor,

arcpy.AddMessage(fc) only gives me the name of 1 shapefile

and

arcpy.AddMessage(projectResult.replace("C:\GIS_Result\","") doesn't work at all .

0 Kudos
DanPatterson_Retired
MVP Emeritus

check my thread, that has already been pointed out, I was hoping he would correct it​ or offer a different solution should mine not be suitable

0 Kudos
MarkWisniewski
New Contributor III

Dan,

I get [u'xyz.shp' ] as the output.

0 Kudos
DanPatterson_Retired
MVP Emeritus

​all that means is Unicode, it won't affect the ability to read the filename, or to use the print statement

>>> a = u'unicode_string'
>>> a
u'unicode_string'
>>> print a
unicode_string
0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi

Try os.path.basename(FileName)  It works for unix too...

Have fun

Mody

0 Kudos