1

I'm building a script tool that creates up to 3 address locators and then uses the output address locators as inputs to the final output composite address locator. The tool executed perfectly prior to adding the code to build the comp address locator. As the tool builds the input address locators in a for loop, I cannot hardcode their names as the first argument for the create composite locator. Instead, I made a list that is populated as the tool loops to make the input address locators:

alNames =[]
for ref in refData:
    baseName = os.path.basename(ref)
    outName = os.path.join(outPath,baseName) #this is the final argument for the create address locator tool

    ...all the code to make the address locator....

    alNames.append(outName)

arcpy.CreateCompositeAddressLocator_geocoding("alNames[0],alNames[1],alNames[2]","Street 'Street or Intersection' true true true 100 Text 0 0 ,First,#,alNames[0],Street,0,0,alNames[1],Street,0,0,alNames[2],Street,0,0;ZIP 'ZIP Code' true true false 10 Text 0 0 ,First,#,alNames[0],ZIP,0,0,alNames[1],ZIP,0,0,alNames[2],ZIP,0,0",outCompAdd)

I'm getting the following error when I run the tool:

Traceback (most recent call last):
  File "N:\Python\Completed scripts\Create_Address_Locators.py", line 34, in <module>
    arcpy.CreateCompositeAddressLocator_geocoding("alNames[0],alNames[1],alNames[2]","Street 'Street or Intersection' true true true 100 Text 0 0 ,First,#,alNames[0],Street,0,0,alNames[1],Street,0,0,alNames[2],Street,0,0;ZIP 'ZIP Code' true true false 10 Text 0 0 ,First,#,alNames[0],ZIP,0,0,alNames[1],ZIP,0,0,alNames[2],ZIP,0,0",outCompAdd)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geocoding.py", line 138, in CreateCompositeAddressLocator
    raise e
ExecuteError: ERROR 000582: Error occurred during execution.

When I run the tool without the quotes around the items from alNames[] I get an error message that the tool only takes up to 4 arguments and I provided 5.

1
  1. Check the elements of the alNames. What do they contain? They should paths to the address locators in a folder or a geodatabase.

  2. When supplying "alNames[0],alNames[1],alNames[2]", separate them with the semicolon ; instead of comma ,.

Check the help page for the tool here, look for code sample. There you see "Atlanta_locator Atlanta;US_Streets_locator US_Streets". Another great way to check the syntax is to run a tool in ArcMap and then right-click the result in the Results window and choose Copy as Python Snippet.

  • Tried using semicolons and got same result. Maybe I'm making this too complicated. I could create the input address locators outside of the loop and just have more code. That way I can use real path names and not indexed items from a list for the first argument when building the composite. – geoJshaun Dec 11 '15 at 17:24
  • That didn't work either. I can get the code to work in the Python command window in ArcMap but the output composite locator doesn't show up in the directory even though a success message that it was created appears. The script fails completely when I run it as a tool. – geoJshaun Dec 11 '15 at 22:29
1

Your first parameter is the string literal "alNames[0],alNames[1],alNames[2]" which is making the tool fail. Assuming this tool behaves like other Arcpy tools, you can join your values into a semicolon-deliminated list like so:

locatorPaths = ";".join(alNames)
arcpy.CreateCompositeAddressLocator_geocoding(locatorPaths, ...)

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.