Need help with ArcGIS developer tools in Visual Studio

1235
14
12-03-2012 05:53 AM
VidmantasAskinis
New Contributor
Hi,

i need help with ArcMap developer tools. I'm trying to make an ArcMap command with Visual Studio 2010 in C# which deletes selected (could be all) points from point set.

I believe it should be a ArcMap basecommand.

I think i need to create an envelope to cover all the points in the layer. Then it should start editing and delete those points. But i'm a newbie at c# and Visual Studio. Could anyone give me code examples of using Ienvelope this way? Or something similar to learn from?
0 Kudos
14 Replies
MarcinDruzgala
Occasional Contributor
The thing is that points should be selected automatically (for example, all points in active view). And then deleted. It seems i forgot to mention it the beginning of this thread 🙂


Ye you did forgot to mention that 🙂
Ok here is the solution:
private IMxDocument MxDoc = ArcMap.Document;

protected override void OnClick()
{
 IActiveView activeView = MxDoc.ActiveView;

 IEnvelope env = activeView.Extent;
 IGeometry geom = (IGeometry)env;
 Map.SelectByShape(geom, null, false);
 activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, env);
}

But here is the thing. It selects all features from ALL layers I don't know if that is a problem but you can later delete features only from one layer. Of course to do that you need to start edit session:)
There is one more option: before selecting by shape you can set the selectable property for feature layers that you don't want to be selected to false. I would do this like this:
IUID uid = new UIDClass();
uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";
IEnumLayer enumLayerByName = Map.get_Layers((UID)uid, true);
enumLayerByName.Reset();
ILayer iLayer = enumLayerByName.Next();
while (!(iLayer == null))
{
 if (iLayer.Name != "your_layer_name")
 {
  IFeatureLayer featLayer= (IFeatureLayer)iLayer;
  featLayer.Selectable = false;
 }
 iLayer = enumLayerByName.Next();
}



Cheers
MDruzgala
0 Kudos
VidmantasAskinis
New Contributor
Now i need help making the code.

You wrote "Map.get_Layers((UID)uid, true);" . Is "Map" an interface (private IMap Map)?
Here too: "Map.SelectByShape(geom, null, false);"

You also wrote   "editor = ArcMap.Application.FindExtensionByCLSID(uidEditor) as IEditor;"   and   "private IMxDocument MxDoc = ArcMap.Document;"  . Is "ArcMap" an "internal static class" like in

internal static class ArcMap
{
  private static IApplication s_app = null;
  private static IDocumentEvents_Event s_docEvent;
}

?
0 Kudos
MarcinDruzgala
Occasional Contributor
Now i need help making the code.

You wrote "Map.get_Layers((UID)uid, true);" . Is "Map" an interface (private IMap Map)?
Here too: "Map.SelectByShape(geom, null, false);"

You also wrote   "editor = ArcMap.Application.FindExtensionByCLSID(uidEditor) as IEditor;"   and   "private IMxDocument MxDoc = ArcMap.Document;"  . Is "ArcMap" an "internal static class" like in

internal static class ArcMap
{
  private static IApplication s_app = null;
  private static IDocumentEvents_Event s_docEvent;
}

?


It's in every simple sample:
private IMap map = ArcMap.Document.FocusMap;


About ArcMap, yes it is this class. It's automatically generated.

MDruzgala
0 Kudos
VidmantasAskinis
New Contributor
Works like a charm 🙂

But i see that it deletes all features (points, polylines etc.). How can i make it to delete only points and leave everything else in place? Add points to pointcollection and then delete? please help 🙂
0 Kudos
MarcinDruzgala
Occasional Contributor
If you want to delete features in specified layer you can do it this way:
privat void DeleteFeatures(IFeatureLayer featLayer)
{
      DeleteFeatures deleteFeatures = new DeleteFeatures();
      deleteFeatures.in_features = featLayer;
      RunTool(GP, deleteFeatures, null);
}


Cheers
MDruzgala
0 Kudos