Passing a path to a variable

3245
2
Jump to solution
12-17-2015 05:39 AM
KONPETROV
Occasional Contributor III

Hello, I have the following code that I am trying to make it work as a tool. If I pass the paths to variables it works perfectly but when I pass them as Tool Parameters when I don't have any result. I don't know what to correct, but there must be some problem with the combination of tool parameter name + "the file a create". I tried also to import it to variable outside tool and then import the variable for use in the tool but nothing changed. This is the code:

import arcpy
import os
from arcpy import env
from arcpy.sa import *


workspace = arcpy.GetParameterAsText(0)
values = arcpy.GetParameterAsText(1)
num_pnts = int(values)
demodel = arcpy.GetParameterAsText(2)
outReclass = Reclassify(demodel, "Value", RemapRange([[100,300,1],[301,500,0]]), "NODATA")
outReclass.save(workspace + "rcls")
n = 0
for i in range(num_pnts):
    n += 1
    # Spatially Balanced Points
    arcpy.CreateSpatiallyBalancedPoints_ga(workspace + "rcls", 1, workspace + "point" + str(n))
    inRaster = workspace + "rcls"
    inObserverFeatures = "point" + str(n) + ".shp"
    outViewshed = Viewshed(inRaster, inObserverFeatures)
    outViewshed.save(workspace + "view" + str(n))
0 Kudos
1 Solution

Accepted Solutions
WesMiller
Regular Contributor III

Try using os.path.join to put together your file paths outViewshed.save(os.path.join(workspace, "view" + str(n)))

View solution in original post

2 Replies
WesMiller
Regular Contributor III

Try using os.path.join to put together your file paths outViewshed.save(os.path.join(workspace, "view" + str(n)))

KONPETROV
Occasional Contributor III
0 Kudos