Select to view content in your preferred language

Create Feature Name from GetParametersAsText()

361
1
04-28-2019 09:08 PM
JCann
by
New Contributor II

New to Python and rarely post here so I am sure my question formatting is not correct. No errors to show because I do because test code runs but returns nothing and no code to post because it is mostly in functions and not tied to the issue. 

I have to "create a fire box feature class name based on the user provided box number". This feature class name will be used as a parameter for a function or assigned a variable that will be used as a parameter in a function (in a script not in a tool) that will check for fields existence and add fields if needed.

I am required to have, boxname = arpy.GetParameterAsText(0) with the input being the "box number", 35 for example.

The feature classes already exist in a geodatabase as FireBoxMap_35 etc. (there are 43 total features), so I know I do not want to replace or add the feature class name into the geodatabase and I can't change the names. 

Previous script in this assignment (without functions), used fcname = arcpyListFeatureClasses("FireBoxMap*") to find all feature classes so I have tried fcname = acrpy.ListFeatureClasses("FireBoxMap*" + boxname) which gives me the correct name but does not work once I pass it to arcpy.ListFields() to test it, no errors, just no fields. Going to test concatenating and SQL queries but have not worked out if that is the way to go here or how to put it together. Any assistance on this would be greatly appreciated. 

0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

ListFeatureClasses—ArcPy Functions | ArcGIS Desktop 

Did you set a workspace?  ie the path to the geodatabase?

If you don't, then just the featureclass name isn't going to do anything, hence this line in the code examples

arcpy.env.workspace = "c:/base/gdb.gdb"

The code snippet up to and including the part where you get the featureclass name and use ListFields would help.

Also, when testing throw in some 'print' statements in before and after using a function to make sure what goes in is correct and what goes out is correct

0 Kudos