Get results from programmatically-launched geoprocessing tool

910
2
05-22-2014 02:05 PM
EvanBlaisdell
New Contributor III
So earlier I figured out how to launch a geoprocessing tool's dialog box from a .NET add-in:

IGPToolCommandHelper cmdHelper = new GPToolCommandHelperClass();
cmdHelper.SetToolByName("MyToolbox.tbx", "MyToolName");
cmdHelper.Invoke(null);


Since then I've tried to use .InvokeModal to retrieve gp messages:

bool ok = true;
ESRI.ArcGIS.Geodatabase.IGPMessages msgs;
msgs = new ESRI.ArcGIS.Geodatabase.GPMessagesClass();
cmdHelper.InvokeModal(0, null, out ok, out msgs);


But the msgs object always returns null.  What I want is essentially the output that appears in the geoprocessing window while the tool is running.  Any ideas?

Thanks,
Evan.
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Evan,

I just tried to replicate your problem in VBA and it returns Nothing, which leads me to think you have discovered a bug.

I thought the approached discussed here may work but that returns Nothing to. I reckon ESRI have broken this interface as this thread I link to has no discussion about the Messages object.

Duncan
0 Kudos
EvanBlaisdell
New Contributor III
Evan,

I just tried to replicate your problem in VBA and it returns Nothing, which leads me to think you have discovered a bug.

I thought the approached discussed here may work but that returns Nothing to. I reckon ESRI have broken this interface as this thread I link to has no discussion about the Messages object.

Duncan


Thanks for investigating Duncan.

I've come up with a bit of a workaround for my purposes.  Get a reference to the Geoprocessor and add a MessagesCreated event handler:

GP = new Geoprocessor();
GP.MessagesCreated += new EventHandler<MessagesCreatedEventArgs>(GP_MessagesCreated);


A rough event handler, just to prove it works and display each message as it's created, looks like this:

void GP_MessagesCreated(object sender, MessagesCreatedEventArgs e)
{
        IGPMessages msgs = e.GPMessages;
        IGPMessage msg = msgs.GetMessage(msgs.Count - 1);
        Debug.Print(msg.Description);
}
   

(And of course unwire the event handler afterward.)

Evan.
0 Kudos