ishan00kaushik

Get selected Feature OID in ArcMap Addin - Java

Discussion created by ishan00kaushik on Jun 29, 2013
Latest reply on Jul 1, 2013 by ldonahue
Hi,

I am trying to built an arcMap Addin tool which on MousePressed event tells me about the selected feature OID.
I have followed following question in the forum but without any luck--

http://forums.arcgis.com/threads/76873-Getting-the-OID-from-a-selected-feature

Till now this is wat my tool do ---

                          public void mousePressed(MouseEvent me) {
        try
        {
          mxDoc = (IMxDocument) app.getDocument();
          IActiveView activeView = mxDoc.getActivatedView();
          IMap map = activeView.getFocusMap();
                        
          IFeatureLayer featureLayer = (IFeatureLayer) mxDoc.getSelectedLayer();

                                  //Getting problem here how to get selected feature in featureLayer
   
   
          mxDoc.getActiveView().refresh();
        }
        catch(Exception ex)
        {
          ex.printStackTrace();
        }
    }


Additionally i tried following methord but nothing happens---

                                      public void mousePressed(MouseEvent me) {
        try
        {
          mxDoc = (IMxDocument) app.getDocument();
          IActiveView activeView = mxDoc.getActivatedView();
          IMap map = activeView.getFocusMap();
    IEnumFeature iefeature = (IEnumFeature) map.getFeatureSelection();
    IFeature ifeature = iefeature.next();
    while(ifeature != null)
    {
     int oid = ifeature.getOID();
     list.add(oid);
     ifeature = iefeature.next();
    }
         
         JOptionPane.showMessageDialog(null, list.get(0));
          mxDoc.getActiveView().refresh();
        }
        catch(Exception ex)
        {
          ex.printStackTrace();
        }
    }

There are less nos of java examples to follow for arcmap addin in java , Can anybody tell me how to get OID of the feature selected.

Outcomes