Wednesday 30 October 2019

Export multiple FC's to cad in arcobjects C#


I am currently trying to export multiple feature classes to a single .dxf via the QuickExport function in the DataInteroperability extension. However this function only converts one FC to one .dxf, ie. One in, one out.


Can someone point me to another function that allows multiple files to be converted to a single output format?


I have tried using a list as an input but to no avail. I know of the ExportToCAD function in python. Is there something similar in C#?.


[EDIT] Here is some code I have been playing around with. I decided to simply use the ExportCAD function in the ESRI.ArcGIS.ConversionTools namespace.


        try
{
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap as IMap;


ITrackCancel tc = new TrackCancel();

for (int i = 0; i < map.LayerCount; i++)
{
List layerInputList = new List();
ILayer pLayer = map.Layer[i];
if (!(pLayer is IGroupLayer))
{
for (int j = 0; j < map.LayerCount; j++)

{
ILayer layer = map.Layer[j];
if (layer is IGroupLayer)
{
IGroupLayer groupLayer = layer as IGroupLayer;
ICompositeLayer compGroupLayer = groupLayer as ICompositeLayer;

for (int k = 0; k < compGroupLayer.Count; k++)
{
ILayer featLayer = compGroupLayer.Layer[k];

layerInputList.Add("C:\\Users\\jhansen\\Documents\\LGA_GDBs\\" + pLayer.Name + ".gdb\\" + featLayer.Name);
}
}
}
Geoprocessor gp = new Geoprocessor();
ExportCAD exportCAD = new ExportCAD();

exportCAD.in_features = layerInputList;
exportCAD.Output_File = "C:\\Users\\jhansen\\Documents\\LGA_GDBs\\" + pLayer.Name + "_CAD.dxf";
exportCAD.Output_Type = "DXF_R14";


gp.Execute(exportCAD, tc);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.Source + "\n\n" + ex.StackTrace);
}


And here is the error I get enter image description here suggesting that it falls over at the gp.execute() line


I suspect this has something to do with the list variable I am using at exportCAD.inputfeatures.



Answer



Per Michael suggestions,


Here is your solution. Copy and paste may not work, since I haven't tested the code


IVariantArray parameters = new VarArrayClass();
parameters.Add(@"D:\mydb.gdb\myFeatuerClass1;D:\mydb.gdb\myFeatuerClass2");
parameters.Add("DWG_R2007");
parameters.Add(@"C:\temp\ExportCAD.DWG");


Geoprocessor gp = new Geoprocessor();
bool response = RunTool("ExportCAD_conversion", parameters, null, false);

public static bool RunTool(string toolName,IVariantArray parameters , ITrackCancel TC, bool showResultDialog)
{
Geoprocessor gp = new Geoprocessor();
IGeoProcessorResult result = null;
// Execute the tool
try
{

result = (IGeoProcessorResult)gp.Execute(toolName, parameters, TC);
string re = result.GetOutput(0).GetAsText();
if (showResultDialog)
ReturnMessages(gp);
if (result.MaxSeverity == 2) //error
return false;
else
return true;
}
catch (COMException err)

{
MessageBox.Show(err.Message + " in RunTool");
ReturnMessages(gp);
}
catch (Exception err)
{
MessageBox.Show(err.Message + " in RunTool");
ReturnMessages(gp);
}
return false;

}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...