Select to view content in your preferred language

Super simple arcpy script using AddMessage

94
2
Jump to solution
Monday
TaiDuong
Emerging Contributor

Apologies for my ignorance (in my defense I'm not a real coder) But can anyone tell me why this very simple script doesn't print the filename when I run the script from the Toolbox. I get the string so my AddMessage is working but not the filename

import arcpy
from sys import argv
 
def Model(RSI_TileSets="RSI_TileSets", Output_Feature_Class="C:\\Users\\john.oliver\\Documents\\ArcGIS\\Projects\\MyProject21\\MyProject21.gdb\\RSI_TileSets_CopyFeatures"😞  # Model
    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = True
    # Process: Copy Features (Copy Features) (management)
    arcpy.management.CopyFeatures(in_features=RSI_TileSets.__str__().format(**locals(),**globals())if isinstance(RSI_TileSets, str) else RSI_TileSets, out_feature_class=Output_Feature_Class.__str__().format(**locals(),**globals())if isinstance(Output_Feature_Class, str) else Output_Feature_Class)
   
    inFile  = arcpy.GetParameterAsText(0)
    arcpy.AddMessage("{0} completed.".format(inFile))
    #
   
if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager(scratchWorkspace="C:\\Users\\john.oliver\\Documents\\ArcGIS\\Projects\\MyProject21\\MyProject21.gdb", workspace="C:\\Users\\john.oliver\\Documents\\ArcGIS\\Projects\\MyProject21\\MyProject21.gdb"😞
        Model(*argv[1:])
   
0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

How was this script generated?  Did you grab it from a model builder output?
I'd guess it's something to do with the getparameter values being out of scope of the function, or that it seems to have hardcoded values into your function - but I'm not too hot on the model builder output 'scripts'.

I'd either really simplify it into a script tool or just use the Parse Path and Add Message functions inside Model Builder.

View solution in original post

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

How was this script generated?  Did you grab it from a model builder output?
I'd guess it's something to do with the getparameter values being out of scope of the function, or that it seems to have hardcoded values into your function - but I'm not too hot on the model builder output 'scripts'.

I'd either really simplify it into a script tool or just use the Parse Path and Add Message functions inside Model Builder.

0 Kudos
TaiDuong
Emerging Contributor

Yes it's the output from ModelBuilder. Edited.  I'll take a look at ModelBuilder AddMessage. Thanks for that.

0 Kudos