dynamic output features name

467
2
03-13-2020 02:16 PM
tamerali
New Contributor III

Hello, I am trying to create a script that allows making a loop inside the data set, using each layer inside it to create a specific report, my question is how can I make the name of the output resulting layer as it matches the name of the input layer like %Name% in model builder. the following is the script.

import arcpy
... arcpy.env.workspace=r'E:\Drawing_id\drawing.gdb'
... listdataset=arcpy.ListDatasets("*","feature")
... listfeature=arcpy.ListFeatureClasses("*","",listdataset)
... for ds in listdataset:
... if ds =='potablwater':
... listfeature=arcpy.ListFeatureClasses("*","",ds)
... for fc in listfeature:
... listfield=arcpy.ListFields(fc)
... for fd in listfield:
... if 'DRAWINGID' in fd.name:
... arcpy.Frequency_analysis(fc,r'C:\Users\aaaaa\Documents\ArcGIS\Default.gdb\??????','DRAWINGID')

thanks

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

Look into the topic of string concatenation. Plenty of examples on the internet.

0 Kudos
curtvprice
MVP Esteemed Contributor
import os
...  (snip)
for fc in listfeature:
    listfield=arcpy.ListFields(fc, 'DRAWINGID')
    if listfield:
        out_tbl = os.path.join(r'C:\Users\aaaaa\Documents\ArcGIS\Default.gdb', 
                      "{}_tbl".format(fc))
        arcpy.Frequency_analysis(fc, out_tbl, 'DRAWINGID')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos