<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help refining a script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419329#M32921</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS!&amp;nbsp; I knew there was a way to do it.&amp;nbsp; I haven't ever used the os module but I will explore this.&amp;nbsp; The fc names I can't change but I can change the .lyr names to match so I will only have one list.&amp;nbsp; you have no idea how giddy this makes me. Ha!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Jul 2015 12:30:54 GMT</pubDate>
    <dc:creator>BradJones</dc:creator>
    <dc:date>2015-07-10T12:30:54Z</dc:date>
    <item>
      <title>Help refining a script</title>
      <link>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419327#M32919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm building a tool where a coworker can enter an ID# (called PWS ID) and then go through choose from a list of features (about 15) they want added from to the map based on the ID#. The tool will select the features based on the ID number, add them as a layer to the map and add the symbology. It wont create any new data, just what is stored in the map memory while it is open. I'm just working on the code at this point. I have a script with A LOT of variables and iterations of arcpy.MakefeatureLayer_management and arcpy.ApplySymbologyFromLayer_managment functions.&amp;nbsp; I know I can hardcode the path to the .lyr files used for symbology, but&amp;nbsp; I'm drawing a blank from there.&amp;nbsp; I'm very much a Python novice and I cant figure out if it can be done by a for loop with arcpy.mapping.ListLayers (for symbology) or some other way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I didn't add the whole script.&amp;nbsp; I left out the code for labels and applying the extent of a layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Import module(s)&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Set overwrite option&lt;/P&gt;&lt;P&gt;env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529;"&gt;# Local variables. Reduce number of variables. Hardcode path for ApplySymbologyFromLayer function or create a list or dictionary?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;pws = "PWS_ID='465'" &lt;SPAN style="color: #7ed529;"&gt;# SQL query.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ass_pws = "PWS_ID1 = '465'" &lt;SPAN style="color: #7ed529;"&gt;# SQL query. Assessment table has different firle dname for PWS ID.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;mtr_recpws = "REC_ID = '465'" &lt;SPAN style="color: #7ed529;"&gt;# SQL query. 'REC_ID" is PWS ID of PWS receiving water through master meter, I assume.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;sources = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\sources" &lt;SPAN style="color: #7ed529;"&gt;# Will need to change if used outside&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; of SWPP staff because of directory permissions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;assessment = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\assessment_areas"&lt;SPAN style="color: #7ed529;"&gt; # Will need to change&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if used outside of SWPP staff because of directory permissions. Assessments not in WATER_FACILITY.gdb.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;srvc_area = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\SERVICE_AREA_COMBO"&lt;/P&gt;&lt;P&gt;bacti = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\BACTI"&lt;/P&gt;&lt;P&gt;wtp = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\WTP"&lt;/P&gt;&lt;P&gt;dbp2 = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\DBP_STAGE2"&lt;/P&gt;&lt;P&gt;dbp = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\DBP"&lt;/P&gt;&lt;P&gt;tank = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\TANK"&lt;/P&gt;&lt;P&gt;valve = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\VALVE_MISCELLANEOUS"&lt;/P&gt;&lt;P&gt;mstr_mtr = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\MASTER_METER"&lt;/P&gt;&lt;P&gt;waterline = "V:\\WATER_FACILITY\\WATERLINES.gdb"&lt;/P&gt;&lt;P&gt;pumpstn = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PUMP_STATION"&lt;/P&gt;&lt;P&gt;prv = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PRV"&lt;/P&gt;&lt;P&gt;press_plane = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PRESSURE_PLANES"&lt;/P&gt;&lt;P&gt;office = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\OFFICE"&lt;/P&gt;&lt;P&gt;src_layer = "Sources"&lt;/P&gt;&lt;P&gt;ass_layer = "Assessment Area"&lt;/P&gt;&lt;P&gt;srvc_layer = "Service Area"&lt;/P&gt;&lt;P&gt;bacti_layer = "Bacti"&lt;/P&gt;&lt;P&gt;wtp_layer = "WTP"&lt;/P&gt;&lt;P&gt;dbp_layer = "DBP"&lt;/P&gt;&lt;P&gt;dbp2_layer = "DBP Stage 2"&lt;/P&gt;&lt;P&gt;tank_layer = "Tank"&lt;/P&gt;&lt;P&gt;valve_layer = "Valve"&lt;/P&gt;&lt;P&gt;mtr_layer = "Master Meter"&lt;/P&gt;&lt;P&gt;line_layer = "Waterline"&lt;/P&gt;&lt;P&gt;pump_layer = "Pump Station"&lt;/P&gt;&lt;P&gt;prv_layer = "PRV"&lt;/P&gt;&lt;P&gt;press_layer = "Pressure Plane"&lt;/P&gt;&lt;P&gt;ofc_layer = "Office"&lt;/P&gt;&lt;P&gt;src_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\SOURCE.lyr"&lt;/P&gt;&lt;P&gt;ass_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\ASSESSMENT.lyr"&lt;/P&gt;&lt;P&gt;wtp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\WTP.lyr"&lt;/P&gt;&lt;P&gt;valve_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\VALVE.lyr"&lt;/P&gt;&lt;P&gt;tank_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\TANK.lyr"&lt;/P&gt;&lt;P&gt;dbp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP.lyr"&lt;/P&gt;&lt;P&gt;dbp2_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP2.lyr"&lt;/P&gt;&lt;P&gt;bacti_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\BACTI.lyr"&lt;/P&gt;&lt;P&gt;mtr_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\MASTER_METER.lyr"&lt;/P&gt;&lt;P&gt;ofc_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\OFFICE.lyr"&lt;/P&gt;&lt;P&gt;prv_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PRV.lyr"&lt;/P&gt;&lt;P&gt;pump_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PUMP.lyr"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5; color: #7ed529;"&gt;# Make feature layers&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(office, ofc_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(press_plane, press_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(srvc_area, srvc_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(mstr_mtr, mtr_layer, mtr_recpws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(pumpstn, pump_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(prv, prv_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(tank, tank_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(valve, valve_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(wtp, wtp_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(dbp, dbp_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(dbp2, dbp2_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(bacti, bacti_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(sources, src_layer, pws)&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(assessment, ass_layer, ass_pws)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529;"&gt;# Apply the symbology from the symbology layer to the input layers&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(src_layer, src_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(ass_layer, ass_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(bacti_layer, bacti_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(wtp_layer, wtp_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(dbp_layer, dbp_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(dbp2_layer, dbp2_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(tank_layer, tank_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(mtr_layer, mtr_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(ofc_layer, ofc_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(prv_layer, prv_symb)&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management(pump_layer, pump_symb)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 20:23:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419327#M32919</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-07-09T20:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help refining a script</title>
      <link>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419328#M32920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this may be useful, although it occurs to me now that you may want to use a dictionary instead of lists:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy

&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;pws = "PWS_ID='465'"&lt;/SPAN&gt;
files = ['&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;DBP_STAGE2&lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;BACTI&lt;/SPAN&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;WTP&lt;/SPAN&gt;', ..., '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;OFFICE&lt;/SPAN&gt;'&lt;/SPAN&gt;] # list all file names
layers = ['&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;DBP Stage 2&lt;/SPAN&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Bacti&lt;/SPAN&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;WTP&lt;/SPAN&gt;', ..., 'Office']
symNames = ['&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;DBP2&lt;/SPAN&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;BACTI&lt;/SPAN&gt;', '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;WTP&lt;/SPAN&gt;', ..., '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;OFFICE&lt;/SPAN&gt;']

root = '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;V:\\WATER_FACILITY\\WATER_FACILITY.gdb'&lt;/SPAN&gt;
paths = []
for file in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.join(root, file)
&amp;nbsp;&amp;nbsp;&amp;nbsp; paths.append(path) # now have list of paths

symRoot = '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;V:\\Source Water Protection\\PWS_ID_Tool'&lt;/SPAN&gt;
symPaths = []
for symName in symNames:
&amp;nbsp;&amp;nbsp;&amp;nbsp; symPath = os.path.join(symRoot, symName) + '.lyr'
&amp;nbsp;&amp;nbsp;&amp;nbsp; symPaths.append(symPath) # now have list of symbol paths

for i in range(len(files)):
&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(paths&lt;I&gt;, layers&lt;I&gt;, pws) # make all the layers&lt;/I&gt;&lt;/I&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management(layers&lt;I&gt;, symPaths&lt;I&gt;) # apply the symbologies&lt;/I&gt;&lt;/I&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideally, your files, layers, etc. would have a consistent naming convention (e.g. all DBP2 files had the name 'DBP2', not "DBP_STAGE2', etc.) so you'd only need one list, but you've got to work with what you've got.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419328#M32920</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T18:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help refining a script</title>
      <link>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419329#M32921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS!&amp;nbsp; I knew there was a way to do it.&amp;nbsp; I haven't ever used the os module but I will explore this.&amp;nbsp; The fc names I can't change but I can change the .lyr names to match so I will only have one list.&amp;nbsp; you have no idea how giddy this makes me. Ha!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 12:30:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-refining-a-script/m-p/419329#M32921</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-07-10T12:30:54Z</dc:date>
    </item>
  </channel>
</rss>

