Should the line of code be encapsulated with f() ?
r"%Value%"[:-8]
In the interest of making it a bit more universal for future use, would the following remove the last 4 characters from a string stored in %Value% ?
r"%Value%"[:-4]
>>> "file.tif"[4] '.' >>> "file.tif"[:-4] 'file' >>> "file.tif"[-4:] '.tif' >>>
f(r"%Value%")
def f(Value): import os return Value[-4]
Can you point me to some documentation, or examples of the expression syntax similar to that above. I'm wanting to do something similar but strip off the last 4 characters of %Value%. So if %Value% = raster.tif, I want to use %Value% plus an expression to get raster.shp
>>> import os >>> os.path.splitext("e:\\work\\image.tif")[0] 'e:\\work\\image'
f(r"%path_element%")
def f(path): import os return os.path.splitext(path)[0]
In ModelBuilder 10.x you can access this value from the feature layer output for the iterator using the Get Field Value tool. The output of that tool will be the value (say, %Name%) you can use in the output file name.Another approach I've used is include the OID and name field in the iterator - then you can parse the value out of the iterator label element using the Calculate Value tool. For example on an iteration the iterator label element may be "1_Foo", you can then use Calculate Value to get the value using this expression: r"%Value%".split("_")[1] the above expression returns "Foo" if Value is "1_Foo".
Thanks for the response. To clarify, I am trying to iterate through feature class using OID, but would like to return Name field in output. sp. Clip%Name%is this possible?
Your question is unclear to me. Have you tried looking at %Value%, which has the value for each iteration?
I am needing help determining syntax of inline variable to use string from field name instead of 1..2...3..
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.