Select to view content in your preferred language

Run model from model builder in python

6844
21
Jump to solution
06-22-2016 08:33 AM
GuillaumeGolay1
Deactivated User

Hi,

I've built a model with model builder. When I run it from model builder it works but now that i've exported it to python, it doesn't work...

Here is my model:

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")

# Local variables:
INTER = "C:\\Users\\w2sohi\\Desktop\\test\\INTER"

# Process: Recréer le localisateur d’adresses
arcpy.RebuildAddressLocator_box(INTER)

It seems that there's a problem with: arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")

I have these error messages:

Traceback (most recent call last):
  File "C:\Users\w2sohi\Desktop\test\recreer.py", line 13, in <module>
    arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 90, in ImportToolbox
    return import_toolbox(input_file, module_name)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 441, in import_toolbox
    mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name, use_alt_alias)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 399, in generate_toolbox_module
    use_alt_alias))
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 391, in <genexpr>
    code = u"\n".join(line if isinstance(line, unicode)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 311, in code_for_toolbox
    yield "__all__ = %r" % ([str(tool.name) for tool in toolbox.tools],)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 3: ordinal not in range(128)

Thank you very much!

Guillaume

0 Kudos
21 Replies
FreddieGibson
Honored Contributor

So it looks like you have a system tool and a model in your toolbox. The problem is that the model within your toolbox is named "Modèle". When you call ImportToolbox this will cause a conflict because identifiers in python 2.X don't support using he character è. If you remove the è the toolbox imports just fine.

2016-06-24_6-24-54.png

GuillaumeGolay1
Deactivated User

oh!

Well done Freddie, thank you!

0 Kudos