Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

So I created an ArcGIS 10 toolbox in ArcSDE and added a tool to it. There are enough examples out there on how to execute a tool.tbx that resides outside SDE or GeoDB. But in C#, how do you use gp.execute on a tool that resides within ArcSDE? thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try using the IToolboxWorkspace interface. Code below works for a file gdb workspace, I'd imagine it would work for arcsde too.

private static void ListToolboxes(IWorkspace ws)
{
    var tbxWkspc = ws as ESRI.ArcGIS.Geoprocessing.IToolboxWorkspace;
    if (tbxWkspc == null)
    {
        Console.WriteLine("not a toolbox workspace");
        return;
    }
    var toolboxes  = tbxWkspc.Toolboxes;
    toolboxes.Reset();
    IGPToolbox tbx;
    while ((tbx = toolboxes.Next()) != null)
    {
        var tools = tbx.Tools;
        tools.Reset();
        IGPTool tool;
        while ((tool = tools.Next()) != null)
        {
            // you could execute here ...
            //tool.Execute
            Console.WriteLine("{0}: {1}", tbx.PathName, tool.Name);
        }
    }            
}
share|improve this answer
    
Works like a charm! I was able to find my toolbox & tool in ArcSDE. Kirk, another question. Instead of enumating thru the tools and finding a hard-coded tool name to execute, could you have the name of the tool in something like a config.xml which you could read? I will probably need to fire different tools so I am looking for flexibility. Or how would you handle this? Thanks! –  saim May 8 '11 at 4:57
    
Sure, you'd need the name of the toolbox and the name of the tool. Open the toolbox with IToolboxWorkspace.OpenToolBox and then open the tool with IToolBox.OpenTool. –  Kirk Kuykendall May 8 '11 at 14:11
    
I ended up using Geoprocessor gp because it was easier. I could not figure out the parameters of IGPTool.execute, because the developer help is vague with no examples. Also, I am running my custom ArcSDE model tool from a console app... Sorry, I must not have been clear. I was wondering if I could save the name of my tool and its parameters to an external xml file so I would never have to update my c# code when a new custom tool is created. thanks! –  saim May 9 '11 at 4:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.