Apply this logic to whatever language you are programming in. I won't speak it's name. 🙂
package gov.gis.leo;
import java.io.IOException;
import javax.swing.JOptionPane;
import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.carto.IActiveView;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.IPageLayout;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.interop.AutomationException;
public class Button1 extends Button {
@Override
public void init(IApplication arg0) throws IOException, AutomationException {
super.init(arg0);
this.app = arg0;
// Initialize our map document
mxDocument = (IMxDocument)app.getDocument();
}
/**
* 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 {
activeView = mxDocument.getActiveView();
if(activeView instanceof IPageLayout){
JOptionPane.showMessageDialog(null, "You are in Page Layout view");
}
if(activeView instanceof IMap){
JOptionPane.showMessageDialog(null, "You are in data view");
}
}
private IMxDocument mxDocument;
private IApplication app;
private IActiveView activeView;
}