Schedule a script: AttributeError: 'module' object has no attribute

3729
3
07-15-2011 03:40 AM
gismoe
by
Occasional Contributor
I want to schedule a script to recreate the cachetiles of an ArcGIS Server.

Here is my script:

import arcpy
arcpy.ImportToolbox(r"C:\Dokumente und Einstellungen\USER\Anwendungsdaten\ESRI\ArcToolbox\ALKIS", "TBX")
arcpy.Cache_recreate_TBX()


This Code should start an Model named Cache_recreate. The Model works fine. But if i start it with py i get this error:

AttributeError: 'module' object has no attribute 'Cache_recreate_TBX'


Any ideas?
Tags (2)
0 Kudos
3 Replies
StacyRendall1
Occasional Contributor III
The error occurs because
arcpy.Cache_recreate_TBX()

is not a valid module within Arcpy. The thing following the . in arcpy.something has to be a module belonging to Arcpy, which in this case it isn't.

You should look through the help files more dor what you are doing.
0 Kudos
gismoe
by
Occasional Contributor
I found this here: http://joelmccune.com/2011/05/05/run-models-as-scheduled-tasks/

The author desrcibes it this way. And it should work. But i'am new to arcpy.
0 Kudos
StacyRendall1
Occasional Contributor III
Ah, I think I have found the problem!

What you see a toolbox model listed as in ArcCatalog/Map is actually just the label for the tool. You have to set the name by right clicking on it in Catalog, then under the General tab editing the Name field.

When a toolbox is imported, its models are added to the arcpy namespace (stuff you can access with the line arcpy.something) by their name plus the toolbox alias you assign when importing it.

So, when you were importing that toolbox the model you wanted was being added to arcpy as something along the lines arcpy.Model_TBX, but you were expecting it to be stored by the label, in this case arcpy.Cache_recreate_TBX...

If you open your toolbox in Catalog and make sure the name is set correctly, not just the label, your model should run fine. Let me know how you get on!