Executing (Message): CalculateValue "\n\n** YOUR PARAMETER IS WEAK **\n** TRY AGAIN\n" # Variant Start Time: Thu Jun 30 10:51:10 2011 Value = ** YOUR PARAMETER IS WEAK ** ** TRY AGAIN ** Succeeded at Thu Jun 30 10:51:10 2011 (Elapsed Time: 0.00 seconds)
All,
I came across this blog about using the Calculate Value tool. The blog is for ArcGIS 10 but I was able to adapt an example to 9.3.
I found this blog really useful as I never knew about this particular tool and being able to write if then else logic but still within model builder is extremely useful as it avoids the need for having to build scripts that are ultimately files that sit outside a toolbox.
So I created a simple python function that tested for the existence of a field and output a boolean which is a precondition for what ever. It all worked great.
Now my question is simple, how do you write a message to the output window when a model is running? If you look at the code below I've tried too methods but it nevers writes anything, is it possible?
The code block contained the following code for the Calculate Value tool:def test(f): import arcgisscripting gp = arcgisscripting.create(9.3) desc = gp.Describe(f) fi = desc.FieldInfo f = fi.FindFieldByName("RIVER") if f == -1: return "False" else: gp.Addmessage("Hello world") print "Hello Word" return "True"
The output in the model dialog is:Executing (Calculate Value): CalculateValue test("%FC%") "def test(f):\n import arcgisscripting\n gp = arcgisscripting.create(9.3)\n desc = gp.Describe(f)\n fi = desc.FieldInfo\n f = fi.FindFieldByName("RIVER")\n if f == -1:\n return "False"\n else:\n gp.Addmessage("Hello world")\n print "Hello Word"\n return "True"" Boolean true Start Time: Thu Jun 30 17:06:39 2011 Value = True Executed (Calculate Value) successfully. End Time: Thu Jun 30 17:06:39 2011 (Elapsed Time: 0.00 seconds) Executing (Get Count): GetCount "Base data\NRFA_Gauge_Locations" 1661 Start Time: Thu Jun 30 17:06:39 2011 Row Count = 1661 Executed (Get Count) successfully. End Time: Thu Jun 30 17:06:39 2011 (Elapsed Time: 0.00 seconds)
As you can see I never see Hello World in the output.
Duncan
In Arc 10 you could create a python script and import it into the toolbox - this is a new functionality that will do what you want. But I do agree that there should be a standard tool for this and voted up your idea!
Here's the online help on embedding scripts in toolboxes.
Usage: ModelMessage <Message_text> {NONE | WARNING | ERROR} {0 | 1 | 2}
Executing: MessageModel Start Time: Fri Jul 01 15:41:02 2011 Executing (Message): ModelMessage "\nHello, world!\n" NONE 0 0 Start Time: Fri Jul 01 15:41:03 2011 Running script ModelMessage... Hello, world! Completed script ModelMessage... Executed (Message) successfully. End Time: Fri Jul 01 15:41:03 2011 (Elapsed Time: 0.00 seconds) Executed (MessageModel) successfully. End Time: Fri Jul 01 15:41:03 2011 (Elapsed Time: 1.00 seconds)
The ability to create script tools ("embed them in a toolbox") has been around since 9.0. If you're on 9.3, you can start with this help topic : An overview of creating script tools
...you can import your .py file into the tool (in fact, you must do this to password protect a script tool). This means you don't have to deliver a separate .py file for your script tool to work, the .py will be saved within the toolbox.