<?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 How to add a string to output filename if an optional arcpy.env.mask is used? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109528#M8454</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In the script below the processing mask is optional. I am trying to identify if a mask was used or not in the output filename. What I have below is not working as it should, as it stands it adds "Mask" to the filename weather or not a processing mask is used. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The behavior I need is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If no processing mask is used =&amp;gt; add nothing to outputRaster filename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If processing mask is used =&amp;gt; add a string ex.Mask to the outputRasterfilename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviously my code needs tweaking (red)! Any Ideas on how to fix this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy modules
import arcpy
from arcpy import env
import sys, string, os
arcpy.env.overwriteOutput = True

# Script arguments
inRaster = arcpy.GetParameterAsText(0)
No_STDEV = arcpy.GetParameterAsText(1)
arcpy.env.mask = arcpy.GetParameterAsText(2)# User sets Geoprocessing/Environments/Workspace #(mask is optional)
if not arcpy.Exists(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results')):
&amp;nbsp;&amp;nbsp; arcpy.CreateFolder_management((os.path.split(arcpy.env.workspace))[0], 'results')
if arcpy.env.mask == "":
&amp;nbsp;&amp;nbsp; proMask= ""
else:
&amp;nbsp;&amp;nbsp; proMask= "Mask"
outputRaster= os.path.join(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results'), (os.path.splitext(os.path.basename(inRaster))[0] + "_" + str(proMask) + str(No_STDEV) + "STDEV_" + "enh.tif"))

# Messages to test string concatenation of output file name and folder creation&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.AddMessage("Name of file to enhance: \n" + inRaster)
arcpy.AddMessage("Name and location of your enhanced image is: \n" + outputRaster)
arcpy.AddMessage("Number of Standard Deviations on the right side to trim histogram: " + No_STDEV)
arcpy.AddMessage("Are you using a processing mask? " + proMask)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:01:42 GMT</pubDate>
    <dc:creator>AliceDeschamps1</dc:creator>
    <dc:date>2021-12-12T16:01:42Z</dc:date>
    <item>
      <title>How to add a string to output filename if an optional arcpy.env.mask is used?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109528#M8454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In the script below the processing mask is optional. I am trying to identify if a mask was used or not in the output filename. What I have below is not working as it should, as it stands it adds "Mask" to the filename weather or not a processing mask is used. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The behavior I need is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If no processing mask is used =&amp;gt; add nothing to outputRaster filename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If processing mask is used =&amp;gt; add a string ex.Mask to the outputRasterfilename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviously my code needs tweaking (red)! Any Ideas on how to fix this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy modules
import arcpy
from arcpy import env
import sys, string, os
arcpy.env.overwriteOutput = True

# Script arguments
inRaster = arcpy.GetParameterAsText(0)
No_STDEV = arcpy.GetParameterAsText(1)
arcpy.env.mask = arcpy.GetParameterAsText(2)# User sets Geoprocessing/Environments/Workspace #(mask is optional)
if not arcpy.Exists(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results')):
&amp;nbsp;&amp;nbsp; arcpy.CreateFolder_management((os.path.split(arcpy.env.workspace))[0], 'results')
if arcpy.env.mask == "":
&amp;nbsp;&amp;nbsp; proMask= ""
else:
&amp;nbsp;&amp;nbsp; proMask= "Mask"
outputRaster= os.path.join(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results'), (os.path.splitext(os.path.basename(inRaster))[0] + "_" + str(proMask) + str(No_STDEV) + "STDEV_" + "enh.tif"))

# Messages to test string concatenation of output file name and folder creation&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.AddMessage("Name of file to enhance: \n" + inRaster)
arcpy.AddMessage("Name and location of your enhanced image is: \n" + outputRaster)
arcpy.AddMessage("Number of Standard Deviations on the right side to trim histogram: " + No_STDEV)
arcpy.AddMessage("Are you using a processing mask? " + proMask)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:01:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109528#M8454</guid>
      <dc:creator>AliceDeschamps1</dc:creator>
      <dc:date>2021-12-12T16:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a string to output filename if an optional arcpy.env.mask is used?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109529#M8455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try using None instead of empty quotes ("")&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if arcpy.env.mask ==&amp;nbsp; None:
&amp;nbsp;&amp;nbsp; proMask= ""
else:
&amp;nbsp;&amp;nbsp; proMask= "Mask"

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109529#M8455</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2021-12-11T06:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a string to output filename if an optional arcpy.env.mask is used?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109530#M8456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That worked like a charm, I knew it could not be that difficult.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help, greatly appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alice&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2011 17:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-string-to-output-filename-if-an/m-p/109530#M8456</guid>
      <dc:creator>AliceDeschamps1</dc:creator>
      <dc:date>2011-07-11T17:32:32Z</dc:date>
    </item>
  </channel>
</rss>

