Select to view content in your preferred language

Help: Using a Parameter variable from Python in Model Builder?

1279
1
07-22-2013 11:11 AM
BrianDonaldson
Emerging Contributor
I am using ArcMap 10 SP5 and wanting to use a couple of parameter varaibles from Python in Model Builder.  In Python they are set up as below:

OutputDatabase = arcpy.GetParameterAsText(0)
ImportTableDatasetVar = arcpy.GetParameterAsText(1)

Script Properties are shown in attachment.

These 2 are set as input, but I have added to output for the model builder custom tool.

I have imported the toolbox as below: (Variables are set in Modelbuilder as standalone workspace variables that are then used by the table to table tool)

AddingTBL = arcpy.ImportToolbox("C:/...../Toolboxname.tbx")
AddingTBL.AddingTables(OutputDatabase, ImportTableDatasetVar)


Any help would be appreciated.

Thanks in advance.

Brian Donaldson
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Honored Contributor
Well, I don't use modelbuilder much only because I prefer to use Python...but I guess modelbuilder is getting stronger so maybe I'll change.

Looks like you've made a script tool, so you can use ImportToolbox to call your custom toolbox your tool resides in....that would be within another script.  It's really just a way to 'connect' scripts you've made into tools, built in 'modular fashion', that otherwise you'd write as one 'main' script.

Neat thing about building models is you're leveraging the 'modularity' so to speak so that you can 'mix' python tools and system tools.
I haven't done this in awhile but I think you'd use one of the set parameter methods to make a variable available for the next connected tool in the modelbuilder environment.  Probably I'm oversimplifying, but think of it this way:  the GetParam methods pass param vars in; the SetParam methods pass param vars out....or 'onward' to the next tool in-process.

SetParameter
Resource Center » Professional Library » Geoprocessing » The ArcPy site package » Functions » Getting and setting parameters
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/SetParameter/000v00000018000000/

In fact, see the whole section in the help tree pertaining to 'Getting and Setting Parameters' -- there's some in there I have no idea about -- for example CopyParameter copies input to output (by index).

Hope that helps,
Wayne

...actually, see the excellent illustration included at this link:
http://gis.stackexchange.com/questions/34872/why-are-results-from-python-tool-not-in-results-window
0 Kudos