0

When I run this tool, I get the error 'name 'locator_AddressLocator_n_' is not defined'.

My guess is that this is an issue with the path where the locator is trying to save to? So, I am assuming I have not set the workspace or the scratch workspace? These are just guesses though.

I will need to save each of the geocoding outputs, so should I just have the code create a new GDB and push the outputs to that location? How could this be accomplished?

import os
import arcpy
from arcpy import env

env.overwriteOutput = 1

Here is the geocoder code:

arcpy.CreateAddressLocator_geocoding("General - Single Field", inputFC+"'Primary Table'", "'Feature ID' '' VISIBLE NONE;*KeyField GeoLabel VISIBLE NONE;'Additional Field' '' VISIBLE NONE;'Altname JoinID' '' VISIBLE NONE", locator_AddressLocator_n_, "")

UPDATE:

Created a GDB from paramter and set the workspace to that location, but I am still getting the same error when running the script. name 'AddressLocator' is not defined

inputGDBname = arcpy.GetParameterAsText(3)
inputGDBloc = arcpy.GetParameterAsText(4)

#Create GDB for address locators
arcpy.CreateFileGDB_management(inputGDBloc, inputGDBname)

env.workspace = inputGDBloc+"/"+inputGDBname

UPDATE

New Error on the last line...

RuntimeError: Object: Error in executing tool

I have included all of my code this time, just so everything is visible to see what could be throwing the error.

import os
import arcpy
from arcpy import env

env.overwriteOutput = 1

#Create GDB for address locators
inputGDBname = arcpy.GetParameterAsText(0)
inputGDBloc = arcpy.GetParameterAsText(1)
arcpy.CreateFileGDB_management(inputGDBloc, inputGDBname)
env.workspace = os.path.join(inputGDBloc, inputGDBname)

#Get FC and Fields
inputFC = arcpy.GetParameterAsText(2)
inputField = arcpy.GetParameterAsText(3)
inputFieldLabel = "GeoLabel"
inputFieldName = arcpy.GetParameterAsText(4)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Calculate the field values for the selected field and populate it with the inputFieldLabel + InputField
rows = arcpy.UpdateCursor(inputFC)
for row in rows:
    idt = row.getValue(inputField)
    exp = inputFieldName + ': ' + idt
    row.setValue('GeoLabel', exp)
    rows.updateRow(row)
del row, rows

Reference_Data = inputFC + ' Primary Table'
RefData = Reference_Data

arcpy.CreateAddressLocator_geocoding("General - Single Field", RefData, "'Feature ID' <None> VISIBLE NONE;*KeyField GeoLabel VISIBLE NONE;'Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE", "Address_Loc_n_", "")
1

try setting up the enviroment

import os
import arcpy
from arcpy import env
env.workspace = "geodatabase file (inculding path)"
env.overwriteOutput = 1
#Here is the geocoder code:

arcpy.CreateAddressLocator_geocoding("General - Single Field", inputFC+"'Primary Table'", "'Feature ID' '' VISIBLE NONE;*KeyField GeoLabel VISIBLE NONE;'Additional Field' '' VISIBLE NONE;'Altname JoinID' '' VISIBLE NONE", locator_AddressLocator_n_, "")

edit: try using the join:

env.workspace = os.path.join(inputGDBloc,inputGDBname)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.