Getting Script Functionality Working In Model

924
8
Jump to solution
01-17-2019 02:45 PM
ChrisHolmes
Occasional Contributor III

Hello,

I have a script tool that is quite simple. It's main purpose is in displaying the following drop down list, the script itself doesn't really do much.

I am using the validation tab in the script tool to put the code to generate the items for the drop down list:

The script itself just displays the name of the selected lucode:

This all works fine on it's own as a script tool. But what I really want to do is to be able to use this list in modelbuilder and have it as a model parameter. As far as I can tell it seems as soon as I drag this script tool onto the modelbuilder interface, I lose the functionality that was available when it was run on it's own as a script tool.

Am I missing something? Is there a way I can get this drop down list displayed in modelbuilder and use it as a model parameter?

Thanks everyone!

0 Kudos
1 Solution

Accepted Solutions
ChrisHolmes
Occasional Contributor III

Hi Randy,

Kind of bizarre, but today for the life of me I cannot find the python script or the script tool in Arcmap (I guess this is what I get for not using a repository). You are correct though in that the second one would be derived output. 

For the moment I'm working on a work around where I've exported the model as a script which should allow me to add the above code into the validation tab. It's too bad that we can't add validation code to the model parameters, it would seem to make sense to be able to do that but I'm sure there's stuff going on that wouldn't allow it in a model that I don't know about?

Thanks!

View solution in original post

8 Replies
ChrisHolmes
Occasional Contributor III

Anybody?

0 Kudos
RandyBurton
MVP Alum

Can you show the parameters tab?  I assume the second parameter is a derived string data type set for output. 

0 Kudos
ChrisHolmes
Occasional Contributor III

Hi Randy,

Kind of bizarre, but today for the life of me I cannot find the python script or the script tool in Arcmap (I guess this is what I get for not using a repository). You are correct though in that the second one would be derived output. 

For the moment I'm working on a work around where I've exported the model as a script which should allow me to add the above code into the validation tab. It's too bad that we can't add validation code to the model parameters, it would seem to make sense to be able to do that but I'm sure there's stuff going on that wouldn't allow it in a model that I don't know about?

Thanks!

curtvprice
MVP Esteemed Contributor

Hi Chris.

It's true that dynamic parameter validation is not possible in Model Builder.  My guess is doing that could make it even slower. 🙂 

Another possible workaround is to create a script tool (with validation included) that imports your toolbox and runs your model tool. (Since export to script is not available in ArcGIS Pro this may be an easier option for Pro users.)

ChrisHolmes
Occasional Contributor III

Thanks Curtis. You make a good point, it likely would add another layer of slowness to the model execution. 

Importing the toolbox is a good idea also. We have yet to fully immerse ourselves in pro yet (just dipped our big toe into it so far!).

0 Kudos
ChrisHolmes
Occasional Contributor III

So I've exported the model to a script and when I try running the script I'm running into the following error:

I'm not sure what it's trying to do. Is it trying to load the AgendaMapping.tbx into memory and running into a problem? I only say that because 'CreateSiteLocation', 'DropDownList', 'EditLuCode', 'Export-OP- are all names of models/scripts that are in AgendaMapping.tbx. Maybe there's something it doesn't like about the 'Export-OP- script? I do have a few scripts that start with Export-OP-. Maybe as a test I should rename them and see if the error continues?

Any other ideas appreciated. Thanks!

0 Kudos
curtvprice
MVP Esteemed Contributor

It looks like you have "-" embedded in a tool name. Tools are implemented as Python functions in arcpy so only alphanumeric characters should be used.

Note the labels (captions) you see when using the toolbox can have spaces and whatnot, I'm talking about the tool name in the model properties.

0 Kudos
ChrisHolmes
Occasional Contributor III

Ahh, got it. Thanks Curtis.

0 Kudos