Select to view content in your preferred language

c# Custom GP function tool - calling another tool in the same DLL

2936
1
05-19-2016 01:25 PM
MarkReddick1
Deactivated User

I'm writing a custom c# GP DLL that defines multiple tools (SolveRoute & CostRoute) that can be added to a toolbox. In some cases they will be run individually in some cases SolveRoute will automatically call CostRoute.

Solve Route does a bunch of Network Analyst stuff and creates some line work.

Cost Route generates associated costing info for that route.

So i have the 2 tool classes defined in one DLL that both implement IGPFunction2, IGPToolBackground and i can see both in the toolbox.

My question though is around how i go about calling the CostRoute tool from within the SolveRoute tool in its Execute method.

I've tried doing something similar to this but even with no params it seems to throw an error.

            IVariantArray parameters = new VarArrayClass();

            // add some params here

            gp.Execute("SolveRoute", parameters, track);

I've seen other code where the tools are created e.g new DeleteFeatures and then the parameters are set. I'm not sure if this the correct way to go. Is there any help documenting this more complex case of a DLL with multiple tools or can anyone give any pointers having done this before?

thanks

mark

0 Kudos
1 Reply
MarkReddick1
Deactivated User

It looks like the correct way to access the secondary tool from within the first tools Execute method is something as follows:

            IGPFunctionFactory gpFuncFact = new YourDLLNamespace.DLLFactory();
            IGPFunction gpFunc = gpFuncFact.GetFunction("CostRoute");   
            gpFunc.Execute(params, track, envMgr, message);

With this form i now see debug messages coming from the called secondary tool function.

0 Kudos