<?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: Convert Python Script to Tool with Parameters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051425#M60904</link>
    <description>&lt;P&gt;Thanks for the idea, but when printing out the parameters, they are all paths:&amp;nbsp;&lt;/P&gt;&lt;P&gt;p(0): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex&lt;BR /&gt;p(1): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb&lt;BR /&gt;p(2): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\Scratch.gdb&lt;BR /&gt;p(3): C:\Users\C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\RoadNetwork\NetworkDataSet&lt;BR /&gt;p(5): C:\UsersC:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\TESTPC&lt;BR /&gt;p(6): 400;800;1000&lt;BR /&gt;p(7): C:\Users\C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\Analysis&lt;/P&gt;&lt;P&gt;I also get the following when printing out the result feature:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;arcgisscripting.ServiceAreaResult object at 0x00000223C8FBAD10&amp;gt;&lt;/PRE&gt;&lt;P&gt;So I believe the 'result' is not empty&lt;/P&gt;</description>
    <pubDate>Mon, 26 Apr 2021 18:05:19 GMT</pubDate>
    <dc:creator>AndrewClark2</dc:creator>
    <dc:date>2021-04-26T18:05:19Z</dc:date>
    <item>
      <title>Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051405#M60902</link>
      <description>&lt;P&gt;HI,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a script that runs perfectly fine using variables for the inputs. As soon as I turn them to parameters, I am running into a "RUN TIME ERROR" with no details. I cannot for the life of me figure out the issue. Any suggestions? The&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy as ap
import numpy as np
import os 

# set environmental variables
ws=ap.GetParameterAsText(0)
gdb = ap.GetParameterAsText(1)
scratch = ap.GetParameterAsText(2)

# Set default geodatabase as workspace
ap.env.workspace = gdb

# Allow files to be overwritten by python code
ap.env.overwriteOutput = True

# Analysis Files
pc = ap.GetParameterAsText(5)
nds = ap.GetParameterAsText(3)
nd_layer_name = "NetworkDataSet"
Output_FD = ap.GetParameterAsText(7)

Imp = ap.GetParameterAsText(6)
Impedance = []
for x in Imp.split(';'):
    Impedance.append(float(x))
    ap.AddMessage(x)
    ap.AddMessage(Impedance)

### School Network Service Area ###

# Create a network dataset layer and get hte desired travel mode
ap.nax.MakeNetworkDatasetLayer(nds,nd_layer_name)
nd_travel_modes = ap.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes[ap.GetParameterAsText(4)]
ap.AddMessage("Create network dataset")

# Instantiate a ServiceArea solver object
service_area = ap.nax.ServiceArea(nd_layer_name)
search_query=[['RoadsNetwork',"'STREET' IS NOT NULL And 'STREET' &amp;lt;&amp;gt; ''"]]
search_criteria=[['RoadsNetwork','SHAPE'],['NetworkDataSet_Junctions','NONE']]
search_tolerance = 500

# Set properties
service_area.distanceUnits = ap.nax.DistanceUnits.Meters
service_area.travelMode = travel_mode
service_area.outputType = ap.nax.ServiceAreaOutputType.Polygons
service_area.geometryAtOverlap = ap.nax.ServiceAreaOverlapGeometry.Overlap
service_area.searchQuery=search_query
service_area.searchTolerance=search_tolerance
service_area.searchToleranceUnits = ap.nax.DistanceUnits.Meters
service_area.polygonBufferDistanceUnits=ap.nax.DistanceUnits.Meters
service_area.polygonBufferDistance=50
service_area.polygonDetail=ap.nax.ServiceAreaPolygonDetail.High

for n in Impedance:
    ap.AddMessage(n)
    service_area.defaultImpedanceCutoffs = [n]

    fd = str(n)+'m'

    fm_fac = service_area.fieldMappings(ap.nax.ServiceAreaInputDataType.Facilities,True)
    fm_fac["Name"].mappedFieldName = 'PCODE'
    ap.AddMessage("Create a network Service Area {} network analysis layer".format(fd))

    # Load Inputs
    service_area.load(ap.nax.ServiceAreaInputDataType.Facilities, pc,field_mappings=fm_fac, append=False)
    ap.AddMessage("Facilities loaded!")
    
    # Solve the analysis
    result = service_area.solve()

    ap.AddMessage("Create a network Service Area {} network analysis layer".format(fd))
    ap.AddMessage(result)
    
    expresult = os.path.join(Output_FD,"RoadNtwkBuf_"+fd)
    
    # Export Feature Class
    result.export(ap.nax.ServiceAreaOutputDataType.Polygons, expresult)
    
    for field in ap.ListFields(expresult):
        ap.AddMessage(field.name)
        if field.required == False:
            if field.name not in ['Name','ToBreak']:
                ap.management.DeleteField(expresult,'{}'.format(field.name))
            
    ap.management.AlterField(expresult,'Name','PCODE',clear_field_alias = "CLEAR_ALIAS")
    ap.management.AlterField(expresult,'ToBreak','BufferSize',clear_field_alias = "CLEAR_ALIAS")
    
    ap.management.CalculateField(expresult,'PCODE','!PCODE![0:6]')
    
    ap.AddMessage('Calculated service area for {}-m service area buffer'.format(n))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "...\Scripts\01_NetworkBuffers.py", line 78, in &amp;lt;module&amp;gt;&lt;BR /&gt;result.export(ap.nax.ServiceAreaOutputDataType.Polygons, expresult)&lt;BR /&gt;RuntimeError&lt;BR /&gt;Failed to execute (NetworkBuffers).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewClark2_1-1619456738747.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/11867i57060766E1393380/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndrewClark2_1-1619456738747.png" alt="AndrewClark2_1-1619456738747.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 17:06:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051405#M60902</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2021-04-26T17:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051418#M60903</link>
      <description>&lt;P&gt;I don't see the full filepaths listed in the tool, looks more like they were dragged as layers - possibly try the full file path for GetParmeterAsText to work, or just as layers/datasets with GetParameter(n).&amp;nbsp; What data types do you have set?&lt;/P&gt;&lt;P&gt;I'd guess this is causing 'result' to be empty.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 17:44:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051418#M60903</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-04-26T17:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051425#M60904</link>
      <description>&lt;P&gt;Thanks for the idea, but when printing out the parameters, they are all paths:&amp;nbsp;&lt;/P&gt;&lt;P&gt;p(0): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex&lt;BR /&gt;p(1): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb&lt;BR /&gt;p(2): C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\Scratch.gdb&lt;BR /&gt;p(3): C:\Users\C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\RoadNetwork\NetworkDataSet&lt;BR /&gt;p(5): C:\UsersC:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\TESTPC&lt;BR /&gt;p(6): 400;800;1000&lt;BR /&gt;p(7): C:\Users\C:\Users\...\03_WorkingData\HEAL_ActiveLivingIndex\HEAL_ActiveLivingIndex.gdb\Analysis&lt;/P&gt;&lt;P&gt;I also get the following when printing out the result feature:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;arcgisscripting.ServiceAreaResult object at 0x00000223C8FBAD10&amp;gt;&lt;/PRE&gt;&lt;P&gt;So I believe the 'result' is not empty&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 18:05:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051425#M60904</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2021-04-26T18:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051455#M60905</link>
      <description>&lt;P&gt;hmm, how about changing the output location to just the GDB, possibly a mix of coordinate systems? What's with &lt;SPAN&gt;C:\Users\C:\Users\ for params 3 and 5?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Although you'd expect it to be the same as the input - and as you ay the tool does work a a standalone script.&lt;/P&gt;&lt;P&gt;I know you have the overwriteOutput set but still try making sure there's no locks/existing data etc. as part of the testing.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 18:54:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051455#M60905</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-04-26T18:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051504#M60907</link>
      <description>&lt;P&gt;parameter 4?&lt;/P&gt;&lt;P&gt;seems to be missing, or it is my eyes&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 20:55:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051504#M60907</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-26T20:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Python Script to Tool with Parameters</title>
      <link>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051554#M60910</link>
      <description>&lt;P&gt;You got it! Projection issue! Local dataset combined with a National dataset so mixing UTM Z17 with Lambert.... so annoying&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 22:51:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-python-script-to-tool-with-parameters/m-p/1051554#M60910</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2021-04-26T22:51:55Z</dc:date>
    </item>
  </channel>
</rss>

