Importing models from a toolbox toolset

966
1
Jump to solution
08-21-2013 01:06 AM
MarcEngelsma1
New Contributor II
Hi there,
In arcgis 10 I'm trying to import a model that's located in a custom toolbox with the arcpy.ImportToolbox method. This is working ok as long as the model is located in the toolbox root but once I put the model in a toolset I'm getting an error:
AttributeError: 'module' object has no attribute 'TestModel_Database'.

Since models in toolbox need to have unique names I assumed the location in a toolset didn't matter but is there some additional info I need to add to the function? I can't seem to find any reference to importing toolsets on the forums, help sites or internet so any info is appreciated.

Below I pasted a piece of code I'm using to test importing a model that creates a featureclass and adds a field.

import arcpy  arcpy.env.overwriteOutput =1  arcpy.ImportToolbox(r"S:\GEOINFO\11_Peilgegevens\PeildataVerwerken")  Parameter01 = "xxTest" Parameter02 = "Testfield"  arcpy.TestModel_Database(Parameter01, Parameter02)


As a bonus question, we're going to upgrade to Arcgis 10. or 10.2 in a couple of months, is this method changing in higher versions? I found a lot of references to python toolboxes so I'm just wondering.

Cheers and thanks in advance for any advice,
Marc
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarcEngelsma1
New Contributor II
Last week I finally solved this problem and I thought I'd post the answer here for future reference.

After sending this question to the ESRI helpdesk I got the confirmation that it was possible to use tools in a toolset and after some more trying and searching I found the problem, I made an error with the toolname.
When you open the tool properties there's is a name field and a label field. For importing tools the only field that matters is the name field and it turns out I was looking to the label field in the catalog view. In my case those were nearly identical but the toolname had a "(2)" behind it due to me copying the tool.

So the moral of this story is to watch your Label and Name fields and in case of toolboxes also the Alias field carefully and it should all work like a charm.

cheers,
Marc

View solution in original post

1 Reply
MarcEngelsma1
New Contributor II
Last week I finally solved this problem and I thought I'd post the answer here for future reference.

After sending this question to the ESRI helpdesk I got the confirmation that it was possible to use tools in a toolset and after some more trying and searching I found the problem, I made an error with the toolname.
When you open the tool properties there's is a name field and a label field. For importing tools the only field that matters is the name field and it turns out I was looking to the label field in the catalog view. In my case those were nearly identical but the toolname had a "(2)" behind it due to me copying the tool.

So the moral of this story is to watch your Label and Name fields and in case of toolboxes also the Alias field carefully and it should all work like a charm.

cheers,
Marc