I am trying to use Merge_Management Geoprocessing tool in arcobject, I want these tool to use layers named "HT Overhead Line" and "HT Underground Line" and create the output out.shp.

Below is the code I am trying which is not working.

        IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
        IMap map = mxdoc.FocusMap;
        if (map.Layer[0] == null)
        { return; }

        IGeoProcessor2 gp = new GeoProcessorClass();
        gp.AddOutputsToMap = true;
        gp.OverwriteOutput = true;
        IVariantArray parameters = new VarArrayClass();

        IGpValueTableObject vt = new GpValueTableObjectClass();
        for (int i = 0; i < map.LayerCount; i++)
            if (map.Layer[i].Name == "HT Overhead Line")
                ILayer HTOverheadLine = map.Layer[i];
                IFeatureLayer fl1 = new FeatureLayerClass();
                fl1 = HTOverheadLine as IFeatureLayer;
                IFeatureClass inFeature1 = fl1.FeatureClass;

                object obj1 = inFeature1;

                if (map.Layer[i].Name == "HT Underground Line")
                    ILayer HTUndergroundLine = map.Layer[i];                       
                    IFeatureLayer fl2 = new FeatureLayerClass();
                    fl2 = HTUndergroundLine as IFeatureLayer;
                    IFeatureClass inFeature2 = fl2.FeatureClass;

                    object obj2 = inFeature2;


        gp.Execute("Merge_management", parameters, null);
  • "OutPath\Out.shp" is not a valid path, should be something like "c:\temp\outpath\out.shp" – Hornbydd Jun 6 '17 at 8:46

You need a temporary workspace before setting up the geoprocessor. And in the end look for the result if job is succeeded. From the workspace you get the result set, so you could do something with it.

// Create a scratch workspace factory.
IScratchWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.ScratchWorkspaceFactoryClass();
IScratchWorkspaceFactory2 workspaceFactory2 = workspaceFactory as IScratchWorkspaceFactory2;

// Get the default scratch workspace.
IWorkspace scratchWorkspace = null;
    if (workspaceFactory2.CurrentScratchWorkspace != null)
        scratchWorkspace = workspaceFactory2.CurrentScratchWorkspace;
    else scratchWorkspace = workspaceFactory2.DefaultScratchWorkspace;
catch (Exception ex)

// Fill your parameters here..

// Execute the tool.
ITrackCancel trac = new ESRI.ArcGIS.Display.CancelTracker();
    ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult resi = gp.Execute(Merge_management", parameters, trac);

    if (resi.Status == esriJobStatus.esriJobSucceeded)
              IEnumDataset arDs = scratchWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
              if (arDs != null)
  • I am getting the same error again , i think the problem persisit in taking two inputs and using it. where i am trying to fit two multiple feature class in IGpValueTableObject vt – Akhil Kumar Jun 8 '17 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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