Error Occurred when Calling Export to CAD Tool in ArcObjects

99
0
12-01-2021 10:33 PM
MatsHardy
Occasional Contributor

I have developed a program to call the "Export To CAD" geoprocessing tool to export the feature classes in personal geodatabase to AutoCAD DWG files. Below are the codes:

private static void ExportToCADByGP(string mdbPath, string fcs, string outputType, string outputFile, string ignorePathsInTables = "Use_Filenames_in_Tables", string appendToExistingFiles = "Overwrite_Existing_Files", string seedFile = "")
{
int i;
IGeoProcessor gp = null;
IGPUtilities gpUtils;
IVariantArray parameters;
StringBuilder gpMsg;

try
{
gp = new GeoProcessor();
gp.SetEnvironmentValue("workspace", mdbPath);
parameters = new VarArray();
parameters.Add(fcs);
parameters.Add(outputType);
parameters.Add(outputFile);
if (string.IsNullOrEmpty(ignorePathsInTables))
{
parameters.Add(ignorePathsInTables);
parameters.Add(appendToExistingFiles);
parameters.Add(seedFile);
}

gp.Execute("ExportCAD_conversion", parameters, null);
parameters.RemoveAll();
gp.ClearMessages();
gpUtils = new GPUtilities();
gpUtils.ReleaseInternals();

Marshal.ReleaseComObject(parameters);
Marshal.ReleaseComObject(gpUtils);
}
catch (Exception ex)
{
if (gp == null)
{
Logger.Debug("ExportCAD: " + ex.Message);
}
else
{
gpMsg = new StringBuilder("Error running Export to CAD\r\n");
for (i = 0; i < gp.MessageCount; i++)
gpMsg.AppendLine(gp.GetMessage(i));
Logger.Debug("ExportCAD: " + gpMsg.ToString());
}
}
}

But when I ran the problem, the exception below occurred occasionally:

Executing: ExportCAD D:\Export\Temp\F_MAIN.shp;D:\Export\Temp\R_MAIN.shp;D:\Export\Temp\temp.mdb\F_AIRVALVE;D:\Export\Temp\temp.mdb\F_CPI;D:\Export\Temp\temp.mdb\F_FITTING;D:\Export\Temp\temp.mdb\F_FLOWCTLVALVE;D:\Export\Temp\temp.mdb\F_HYDRANT;D:\Export\Temp\temp.mdb\F_MANHOLE;D:\Export\Temp\temp.mdb\F_MANHOLE_PY;D:\Export\Temp\temp.mdb\F_METER;D:\Export\Temp\temp.mdb\F_MISC_PT;D:\Export\Temp\temp.mdb\F_MISCINSTALL_PY;D:\Export\Temp\temp.mdb\F_MSC_LN;D:\Export\Temp\temp.mdb\F_PUMPSTN_PY;D:\Export\Temp\temp.mdb\F_SVCRSVRTNK_PY;D:\Export\Temp\temp.mdb\F_TRTWKS_PY;D:\Export\Temp\temp.mdb\R_AIRVALVE;D:\Export\Temp\temp.mdb\R_CPI;D:\Export\Temp\temp.mdb\R_FITTING;D:\Export\Temp\temp.mdb\R_FLOWCTLVALVE;D:\Export\Temp\temp.mdb\R_HYDRANT;D:\Export\Temp\temp.mdb\R_MANHOLE;D:\Export\Temp\temp.mdb\R_MANHOLE_PY;D:\Export\Temp\temp.mdb\R_METER;D:\Export\Temp\temp.mdb\R_MISC_PT;D:\Export\Temp\temp.mdb\R_MISCINSTALL_PY;D:\Export\Temp\temp.mdb\R_PUMPSTN_PY;D:\Export\Temp\temp.mdb\R_SVCRSVRTNK_PY;D:\Export\Temp\temp.mdb\R_RESERVOIR_PY;D:\Export\Temp\temp.mdb\R_TRTWKS_PY;D:\Export\Temp\temp.mdb\F_TEMP_POINT;D:\Export\Temp\temp.mdb\R_TEMP_POINT;D:\Export\Temp\temp.mdb\F_ANNO_POINT;D:\Export\Temp\temp.mdb\F_TEMP_LINE;D:\Export\Temp\temp.mdb\R_TEMP_LINE DWG_R2000 D:\Jimmy\F07-SW-16A.DWG Ignore_Filenames_in_Tables Overwrite_Existing_Files D:\Export\Temp\template.dwg
Start Time: Thu Dec 2 10:03:49 2021
...Exporting D:\Export\Temp\F_MAIN.shp to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\R_MAIN.shp to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_AIRVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_CPI to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_FITTING to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_FLOWCTLVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_HYDRANT to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MANHOLE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MANHOLE_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_METER to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MISC_PT to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MISCINSTALL_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MSC_LN to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_PUMPSTN_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_SVCRSVRTNK_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\F_TRTWKS_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_AIRVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_CPI to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_FITTING to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_FLOWCTLVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_HYDRANT to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_MANHOLE to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_MANHOLE_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_METER to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_MISC_PT to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
...Exporting D:\Export\Temp\temp.mdb\R_MISCINSTALL_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16A.DWG
ERROR 000508: Unable to create D:\Jimmy\F07-SW-16A.DWG: Failure During Save
Failed to execute (ExportCAD).
Failed at Thu Dec 2 10:03:57 2021 (Elapsed Time: 8.81 seconds)

Executing: ExportCAD D:\Export\Temp\F_MAIN.shp;D:\Export\Temp\R_MAIN.shp;D:\Export\Temp\temp.mdb\F_AIRVALVE;D:\Export\Temp\temp.mdb\F_CPI;D:\Export\Temp\temp.mdb\F_FITTING;D:\Export\Temp\temp.mdb\F_FLOWCTLVALVE;D:\Export\Temp\temp.mdb\F_HYDRANT;D:\Export\Temp\temp.mdb\F_MANHOLE;D:\Export\Temp\temp.mdb\F_MANHOLE_PY;D:\Export\Temp\temp.mdb\F_METER;D:\Export\Temp\temp.mdb\F_MISC_PT;D:\Export\Temp\temp.mdb\F_MISCINSTALL_PY;D:\Export\Temp\temp.mdb\F_MSC_LN;D:\Export\Temp\temp.mdb\F_PUMPSTN_PY;D:\Export\Temp\temp.mdb\F_SVCRSVRTNK_PY;D:\Export\Temp\temp.mdb\F_TRTWKS_PY;D:\Export\Temp\temp.mdb\R_AIRVALVE;D:\Export\Temp\temp.mdb\R_CPI;D:\Export\Temp\temp.mdb\R_FITTING;D:\Export\Temp\temp.mdb\R_FLOWCTLVALVE;D:\Export\Temp\temp.mdb\R_HYDRANT;D:\Export\Temp\temp.mdb\R_MANHOLE;D:\Export\Temp\temp.mdb\R_MANHOLE_PY;D:\Export\Temp\temp.mdb\R_METER;D:\Export\Temp\temp.mdb\R_MISC_PT;D:\Export\Temp\temp.mdb\R_MISCINSTALL_PY;D:\Export\Temp\temp.mdb\R_PUMPSTN_PY;D:\Export\Temp\temp.mdb\R_SVCRSVRTNK_PY;D:\Export\Temp\temp.mdb\R_RESERVOIR_PY;D:\Export\Temp\temp.mdb\R_TRTWKS_PY;D:\Export\Temp\temp.mdb\F_TEMP_POINT;D:\Export\Temp\temp.mdb\R_TEMP_POINT;D:\Export\Temp\temp.mdb\F_ANNO_POINT;D:\Export\Temp\temp.mdb\F_TEMP_LINE;D:\Export\Temp\temp.mdb\R_TEMP_LINE DWG_R2000 D:\Jimmy\F07-SW-16B.DWG Ignore_Filenames_in_Tables Overwrite_Existing_Files D:\Export\Temp\template.dwg
Start Time: Thu Dec 2 10:09:00 2021
...Exporting D:\Export\Temp\F_MAIN.shp to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\R_MAIN.shp to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_AIRVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_CPI to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_FITTING to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_FLOWCTLVALVE to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_HYDRANT to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MANHOLE to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MANHOLE_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_METER to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MISC_PT to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MISCINSTALL_PY to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
...Exporting D:\Export\Temp\temp.mdb\F_MSC_LN to CAD
.....exporting to D:\Jimmy\F07-SW-16B.DWG
ERROR 000508: Unable to create D:\Jimmy\F07-SW-16B.DWG: Failure During Save
Failed to execute (ExportCAD).
Failed at Thu Dec 2 10:09:03 2021 (Elapsed Time: 3.78 seconds)

But after I ran the program repeatedly several times. DWG files can be exported without error.

Anyone has ideas where the problem is?

0 Kudos
0 Replies