run a model from python problem

802
8
02-26-2014 01:14 AM
derekbigwood
New Contributor II
I am using arcGIS 10.0 SP5

I have the following code :

import arcpy

arcpy.ImportToolbox(r"C:\Documents and Settings\Derek\FRAME\FORTEST.tbx", "Derek")

arcpy.TEST_Derek()

The model is names  TEST
The toolbox alias is  Derek

When I try and run this I get an error

AttributeError: 'module' object has no attribute 'TEST_Derek"

What I want to do is to run the model TEST from the toolbox FORTEST

I have tried the same code using arcGIS 10.1 and it runs perfectly. is there something different in arcGIS10.0 and is there a workaround?

Any help would be appreciated

Thanks

Derek
Tags (2)
0 Kudos
8 Replies
MathewCoyle
Frequent Contributor
If the toolbox was created in 10.1 then 10.0 cannot read from it.
0 Kudos
derekbigwood
New Contributor II
The model was created in arcGIS 10.0 and needs to run in version 10.0. I just tested it on arcGIS 10.1 to see if it would run.
0 Kudos
derekbigwood
New Contributor II
The toolbox qas created in 10.0 and only tested in 10.1

Cannot figure out why the same code will not run in 10.0
0 Kudos
MathewCoyle
Frequent Contributor
Try removing the toolbox alias.
arcpy.ImportToolbox(r"C:\Documents and Settings\Derek\FRAME\FORTEST.tbx")
...
arcpy.TEST()


Also try recreating the toolbox and model in 10.0 and not touching it with 10.1. Can you run the model from ArcMap 10.0?
0 Kudos
derekbigwood
New Contributor II
Thanks for the suggestions and I have tried them but am still getting an error message. I think that maybe something has changed with the python between 10.0 and 10.1
0 Kudos
MathewCoyle
Frequent Contributor
There were many things that changed with Python between 10.0 and 10.1. That shouldn't stop you from importing the model though. Can you post your toolbox and model?
0 Kudos
FreddieGibson
Occasional Contributor III
If you're unable to provide the toolbox for us to review, I would suggest doing the following:

1. Open the Python Window in ArcMap at 10.0 and drag the model into the Python Window.  This will allow you to see the name that is  currently assigned to the Model you're trying to utilize.

2. Open the the properties of your *.tbx in the Catalog Window, assign a very unique alias there, then import the toolbox and use the arcpy.ListTools('*_yourAlias') function to see what tools the system shows available with that alias.

3. Does your model use any extensions (i.e. Network Analyst, Spatial Analyst, etc.) that you don't have enabled or any tools that require a higher license level than what you have assigned at 10.0?  If you import a toolbox before you set the appropriate permissions it would hide the tool from the system.

For the most part, opening the toolbox at 10.1 or 10.2 wouldn't cause the toolbox to be unreadable at 10.0 as long as the toolbox was created or saved in 10.0 and you haven't saved/modified the toolbox/model in a higher release. On the other hand, it is sometimes the best option to just create a new toolbox, create a new model, and then copy and paste your original models components into the new model.
curtvprice
MVP Esteemed Contributor
2. Open the the properties of your *.tbx in the Catalog Window, assign a very unique alias there


Derek,

Freddie brings up a good point here, although he has crossed the line by adding a modifier to the word "unique" (Mr. Language person reminds us that something is either unique or not unique, there is no in between; "peculiar" would be more accurate, but has negative connotations. But I digress.  Sorry, I hear this on the TV machine all the time and it's a family heirloom pet peeve.)

I'm guessing that on your 10.0 session you have two toolboxes with the same alias loaded in your ArcMap session or arcpy. If you have a tool name that is not unique between the toolboxes, arcpy will not be able to resolve the tool name and it comes up missing. I wish arcpy.ImportToolbox() checked for this problem and printed a warning. In fact, I am going to go drop that on ideas.esri.com right now. Please vote it up.

Here's a simple example of the problem. I have two simple toolboxes.

Toolbox1.tbx
--> Model1
Toolbox2.tbx
--> Model1
--> Model2

>>> arcpy.ImportToolbox(r"D:\Users\cprice\work\Toolbox1.tbx","Derek")
<module 'Derek' (built-in)>
>>> dir(arcpy.Derek)
['Model1', '__alias__', '__all__', '__builtins__', '__doc__', '__name__', '__package__', '__pathname__']
>>> arcpy.ImportToolbox(r"D:\Users\cprice\work\Toolbox2.tbx","Derek")
<module 'Derek' (built-in)>
>>> dir(arcpy.Derek)
['Model1', 'Model2', '__alias__', '__all__', '__builtins__', '__doc__', '__name__', '__package__', '__pathname__']
>>> arcpy.Derek.__all__
['Model1', 'Model2', 'Model1']  


The tool list is now non-unique so arcpy cannot find Model1 (but Model2 is OK):

>>> arcpy.Model1_Derek()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Users\cprice\work\Toolbox2.tbx", line 21, in Model1
AttributeError: Object: Tool or environment <Model1_Derek> not found
>>> arcpy.Model2_Derek()
<Result ''>


To fix the issue, drop the toolbox and start again:
>>> del arcpy.Derek
>>> arcpy.ImportToolbox(r"D:\Users\cprice\work\Toolbox2.tbx","Derek")
<module 'Derek' (built-in)>
>>> arcpy.Derek.__all__
['Model2', 'Model1']
>>> arcpy.Model1_Derek()
<Result ''>