Select to view content in your preferred language

Why doesn't this code work for Geoprocess Tool???

2401
5
01-12-2011 03:24 AM
JoshV
by
Regular Contributor
I'm using ArcGIS 10 and my script is just a C# standalone console app.
In using the below code, it bombs on the gp.Execute line suggesting "Error HRESULT E_FAIL has been returned from a call to a COM component".  The Source path and the Target path appear to be correct.  Ideas anyone??  Thanks

 ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                gp.OverwriteOutput = true;
                ESRI.ArcGIS.ConversionTools.MetadataImporter MI = new MetadataImporter();
                MI.source = "K:\\GISTeam\\Data Services\\GIS Data\\Metadata\\PilotsFieldsUnits.xml";
                MI.target = "Database Connections\\SERVER-SQLPRD10 (devgis - sde).sde\\sde.DEVGIS.DevelopmentAndTesting\\sde.DEVGIS.PilotsFieldsUnits";
                gp.Execute(MI, null);
0 Kudos
5 Replies
LukeBadgerow
Deactivated User
I'm finding that even though the resource center indicates that calling the tool the way you're doing that below

ESRI.ArcGIS.ConversionTools.MetadataImporter MI = new MetadataImporter();


has yet to work for me.  I have had success when I call the tool by string as the first parameter of the Execute method... an example from one of my projects:

                    IVariantArray parameters = new VarArrayClass();
                    parameters.Add(inFC);
                    //parameters.Add(outFC);
                    parameters.Add(outworkspace);
                    parameters.Add(outshapefile);
                    parameters.Add(" ");
                    //parameters.Add("NO_TEST");
                    parameters.Add(fieldmapping);

                    ...

                object severity = 2;
                try
                {
                    //if(!gp.Exists(outshapefile))
                    gp.Execute("FeatureclassToFeatureclass_conversion", parameters, null);
                    //gp.Execute("append_management", parameters, null);
                    fieldmapping.RemoveAll();
                }
                catch
                {
                    
                    Console.WriteLine(gp.GetMessages(ref severity).ToString());
                }


so I'm guessing you're going to want to set it up something like this:

ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                gp.OverwriteOutput = true;
                
                IVariantArray parameters = new IVariantArrayClass();
                parameters.Add("K:\\GISTeam\\Data Services\\GIS Data\\Metadata\\PilotsFieldsUnits.xml");
                parameters.Add("Database Connections\\SERVER-SQLPRD10 (devgis - sde).sde\\sde.DEVGIS.DevelopmentAndTesting\\sde.DEVGIS.PilotsFieldsUnits");

                 gp.Execute("MetadataImporter_conversion", parameters, null);


good luck, I hope this helps
0 Kudos
JoshV
by
Regular Contributor
I'm finding that even though the resource center indicates that calling the tool the way you're doing that below

ESRI.ArcGIS.ConversionTools.MetadataImporter MI = new MetadataImporter();


has yet to work for me.  I have had success when I call the tool by string as the first parameter of the Execute method... an example from one of my projects:

                    IVariantArray parameters = new VarArrayClass();
                    parameters.Add(inFC);
                    //parameters.Add(outFC);
                    parameters.Add(outworkspace);
                    parameters.Add(outshapefile);
                    parameters.Add(" ");
                    //parameters.Add("NO_TEST");
                    parameters.Add(fieldmapping);

                    ...

                object severity = 2;
                try
                {
                    //if(!gp.Exists(outshapefile))
                    gp.Execute("FeatureclassToFeatureclass_conversion", parameters, null);
                    //gp.Execute("append_management", parameters, null);
                    fieldmapping.RemoveAll();
                }
                catch
                {
                    
                    Console.WriteLine(gp.GetMessages(ref severity).ToString());
                }


so I'm guessing you're going to want to set it up something like this:

ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                gp.OverwriteOutput = true;
                
                IVariantArray parameters = new IVariantArrayClass();
                parameters.Add("K:\\GISTeam\\Data Services\\GIS Data\\Metadata\\PilotsFieldsUnits.xml");
                parameters.Add("Database Connections\\SERVER-SQLPRD10 (devgis - sde).sde\\sde.DEVGIS.DevelopmentAndTesting\\sde.DEVGIS.PilotsFieldsUnits");

                 gp.Execute("MetadataImporter_conversion", parameters, null);


good luck, I hope this helps


Hi Luke-  Thanks for the fast reply.  I'm having a little trouble locating the IVariantArrayClass.  I found IVariantArray as part of the esriSystem reference.  Thoughts?
0 Kudos
JoshV
by
Regular Contributor
Hi Luke-  I used VarArrayClass and then ran my code again but still got the same error.  I'll keep trying.  This is Strange..
0 Kudos
LukeBadgerow
Deactivated User
it should be spitting out a long int error number.  I was getting the same response, if you wrap it up in the try block and catch the gp messages you may be able to track down whether if it's a syntax or other issue on the Execute method, or if your parameters aren't built just right. 

I noticed with some of mine that even though it looks like the parameter array looks like it wants the String reference to the input parameter, it may actually be looking for an object of whatever type you're trying to pass.   So in your case it might actually be looking for an XML Document.  I might try something like this:

XmlDocument doc = new XmlDocument();
doc.Load("K:\\GISTeam\\Data Services\\GIS Data\\Metadata\\PilotsFieldsUnits.xml")


(you've got to love building a test environment for allowing the time to look at other code)
0 Kudos
NeilClemmons
Honored Contributor
Just a quick check:  are you binding to the Desktop product runtime and then checking out a license at the appropriate level before running this code?  Standalone applications must do this before making any ArcObjects calls or they will not run properly.
0 Kudos