1

I am building a custom arcMap Addin button which onclick event tells info about selected features.

Following is my java class ---

public class Break extends Button {

/**
 * Called when the button is clicked.
 * 
 * @exception java.io.IOException if there are interop problems.
 * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
 */
@Override
public void onClick() throws IOException, AutomationException {
    // TODO Auto-generated method stub


    MapBean mapBean = new MapBean();
    try{
        IMap map = mapBean.getMap();
        ISelection selection = map.getFeatureSelection();
        IEnumFeature enumFeature = (IEnumFeature)selection;
        enumFeature.reset();
        IFeature feature = enumFeature.next();
        while (feature != null){
            System.out.println("FEATURE ID: " + feature.getOID());
            feature = enumFeature.next();
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
    }
}   

I implimented the button on ArcMap but nothing seems to work onclick event , might be its not getting the ArcMap at all.Could anybody tell how to resolve this issue.

Thanks in advance////

2 Answers 2

1

@Andrew Rohne is correct, you first need to get reference to the application then the mxdoc within your click event method. Here is an example below (in vb.net though):

Public Shared gApp As IApplication
Public Shared gMxDoc As IMxDocument

 Protected Overrides Sub OnClick()
        Try
            gApp = CType(Hook, IApplication)
            gMxDoc = CType(My.ArcMap.Application.Document, IMxDocument)

            'your logic here

            My.ArcMap.Application.CurrentTool = Nothing

        Catch ex As Exception
            MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
        End Try
 Emd Sub
0

Do you have:

@Override
public void init(IApplication app) throws IOException, AutomationException {
    this.app = app;
    super.init(app);
}

In your class?

You would need to have an application object in the class:

public class Break extends Button {
    private IApplication app; //<~ Add this too
    @Override
    public void onClick() throws IOException, AutomationException {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.