Hello, I implement following code to make add-in for ArcMap. After user inputs from 'newform' window, geoprocessors do their job. But when I run this code, ArcMap just crashed without any message or report. I tried to debug it, but it's just same. Crashed. I checked debug setting, it was fine, exactly same as ESRI's instruction on web resource. I will add more code after this, but crashing without any report like this, I cannot do programing? It would be helpful if I know1) why does current code make crash?2) how can I debug add-in and find what is a problem, not just crash without any clue? Thanks
namespace Convexpath_mk2
{
public class runConvexPath : ESRI.ArcGIS.Desktop.AddIns.Button
{
IGeoProcessor2 gp;
IGeoProcessorResult result;
IVariantArray parameters;
struct pair
{
//definition of pair data type
}
struct coords
{
//definition of coords data type
}
public runConvexPath()
{
gp = new GeoProcessorClass();
parameters = new VarArrayClass();
}
protected override void OnClick()
{
ConvexPathForm newForm = new ConvexPathForm();
newForm.Text = "Test";
newForm.ShowDialog();
Dictionary<string, string> fcDict = new Dictionary<string, string>();
fcDict = newForm.caDi();
string path = fcDict["path"];
gp.SetEnvironmentValue("workspace", path);
gp.OverwriteOutput = true;
gp.AddOutputsToMap = false;
List<string> oriList = new List<string>();
List<string> desList = new List<string>();
Dictionary<pair, pairData> pairDict = new Dictionary<pair, pairData>();
List<pair> pairList = new List<pair>();
Dictionary<string, string> belongDict = new Dictionary<string,string>();;
FCUtils fcUtils = new FCUtils();
string idxOrigin = fcDict["idxOrigin"];
string idxDestine = fcDict["idxDestine"];
//Making Map boundary (polyline)
string strBoundaryline = "boundaryline";
parameters = new VarArrayClass();
parameters.Add(fcDict["fcBoundary"]);
parameters.Add(strBoundaryline);
gp.Execute("FeatureToLine_management", parameters, null);
//Making Barrier boundary (polyline)
string strBarrierline = "barrierline";
parameters = new VarArrayClass();
parameters.Add(fcDict["fcInsideBarriers"]);
parameters.Add(strBarrierline);
gp.Execute("FeatureToLine_management", parameters, null);
//Making boundary vertices (point)
string strBoundaryVertices = "boundaryVertices";
parameters = new VarArrayClass();
parameters.Add(fcDict["fcBoundary"]);
parameters.Add(strBoundaryVertices);
gp.Execute("FeatureVerticesToPoints_management", parameters, null);
//Making fcMerged
string strMerged = "merged";
parameters = new VarArrayClass();
List <string> merged = new List<string>();
merged.Add(fcDict["fcOrigin"]);
merged.Add(fcDict["fcDestine"]);
parameters.Add(merged);
parameters.Add(strMerged);
gp.Execute("Merge_management", parameters, null);
//Making fcFillBoundary
string strFillBoundary = "FillBoundary";
parameters = new VarArrayClass();
parameters.Add(fcDict["fcBoundary"]);
parameters.Add(strFillBoundary);
gp.Execute("EliminatePolygonPart_management", parameters, null);
//Making index field for boundary vertices
try
{
parameters = new VarArrayClass();
parameters.Add(strBoundaryVertices);
parameters.Add("id_f");
parameters.Add("SHORT");
gp.Execute("AddField_management", parameters, null);
}
catch (COMException comExc)
{
string errMsg = comExc.Message;
}
parameters = new VarArrayClass();
parameters.Add(strBoundaryVertices);
parameters.Add("id_f");
parameters.Add("[OBJECTID]");
parameters.Add("VB");
gp.Execute("CalculateField_management", parameters, null);
IGPUtilities2 gpUtils = new GPUtilitiesClass();
gpUtils.Workspace = path;
IFeatureClass fcOrigin = gpUtils.OpenFeatureClassFromString(fcDict["fcOrigin"]);
IFeatureClass fcDestine = gpUtils.OpenFeatureClassFromString(fcDict["fcDestine"]);
IFeatureClass fcBoundary = gpUtils.OpenFeatureClassFromString(fcDict["fcBoundary"]);
IFeatureClass fcBarrier = gpUtils.OpenFeatureClassFromString(fcDict["fcBarrier"]);
IFeatureClass fcBoundaryLine = gpUtils.OpenFeatureClassFromString(strBoundaryline);
IFeatureClass fcBarrierLine = gpUtils.OpenFeatureClassFromString(strBarrierline);
IFeatureClass fcBoundaryVertices = gpUtils.OpenFeatureClassFromString(strBoundaryVertices);
IFeatureClass fcMerged = gpUtils.OpenFeatureClassFromString(strMerged);
IFeatureCursor curBoundaryVertices;
IFeature ifBoundaryVertices = null;
IFeatureCursor oriCursor;
IFeatureCursor desCursor;
string oid;
IFeature feature = null;
oriCursor = fcOrigin.Search(null, false);
int idFcOrigin_id_f = fcOrigin.Fields.FindField(idxOrigin);
try
{
while ((feature = oriCursor.NextFeature()) != null)
{
oid = (string)feature.get_Value(idFcOrigin_id_f);
oriList.Add(oid);
belongDict[oid] = "orgin";
}
Marshal.ReleaseComObject(oriCursor);
}
catch (COMException comExc)
{
string errMsg = comExc.Message;
}
desCursor = fcDestine.Search(null, false);
try
{
while ((feature = desCursor.NextFeature()) != null)
{
oid = (string)feature.get_Value((feature.Fields.FindField(idxDestine)));
desList.Add(oid);
belongDict[oid] = "destine";
}
Marshal.ReleaseComObject(desCursor);
}
catch (COMException comExc)
{
string errMsg = comExc.Message;
}
foreach (string i in oriList)
{
foreach (string j in desList)
{
pair pKey = new pair(i, j);
pairList.Add(pKey);
}
}
List<string> lines = new List<string>();
int total_edges = 0;
long start_clip = DateTime.Now.Ticks;
foreach (pair i in pairList)
{
double euDistance = 0;
IGeometry geo = new MultipointClass();
IPointCollection5 pcTempPair = geo as IPointCollection5;
ISpatialFilter sFilter1 = new SpatialFilterClass();
sFilter1.GeometryField = fcMerged.ShapeFieldName;
sFilter1.WhereClause = "id_f = '" + i.getOri + "' OR id_f = '" + i.getDes + "'";
IFeatureCursor curMerged3 = fcMerged.Search(sFilter1, false);
IFeature ifMerged = null;
while ((ifMerged = curMerged3.NextFeature()) != null)
{
IPoint ptIn = new PointClass();
ptIn = (IPoint)ifMerged.ShapeCopy;
pcTempPair.AddPoint(ptIn);
}
}
}
protected override void OnUpdate()
{
Enabled = ArcMap.Application != null;
}
}
}