Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document.

Similar presentations


Presentation on theme: "Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document."— Presentation transcript:

1 Arc: Accessing the Framework Dr Andy Evans

2 Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document Ask Document for Maps Ask Maps for a Map Ask Map for Layers Ask Layers for Layer etc. The running version of Arc is accessed via gatekeeper objects. You then request objects from these, and subsequent objects from the objects you get back.

3 init(IApplication app) Most addIns come with a init method that can be overridden. This is sent the application as an entry point for the running framework. import com.esri.arcgis.framework.*; private IApplication app; @Override public void init(IApplication app){ this.app = app; }

4 Document You can use this to get hold of the current document. This is the current data and GUI. import com.esri.arcgis.arcmapui.*; IMxDocument mxDoc = (IMxDocument)app.getDocument();

5 API It is then just a matter of finding how to do stuff in the API docs: http://resources.arcgis.com/en/help/arcobjects- java/api/arcobjects/index.html

6 N.B. The code utilises Java Annotations. @name Used as a marker for software intending to process the code. @Override

7 N.B.II Arc returns objects that implement multiple interfaces. You generally cast the object to a specific interface when using it. IMxDocument mxDoc = (IMxDocument)app.getDocument(); There is nothing to stop you recasting it to another interface to use different methods in it: IDocument iDoc = (IDocument) mxDoc; Infact, it is very common.

8 The COM In Microsoft languages, this reassignment of interface labels is key. It allows chunks of code to use other chunks of code without knowing anything other than the interface names. It is used to hold together a great deal of the Component Object Model (COM) at the heart of Microsoft software. ArcGIS is built around the COM, so this is a common thing to see.

9 Interfaces This requires some care. You might think that redefining everything as the right object would be sensible: public void init(IApplication app){ Application a = (Application)app; You could then use all the methods. However, while objects Arc gives you will match the interfaces, they may not do anything sensible.

10 Interfaces For example, this works in ArcMap: public void init(IApplication app){ Application a = (Application)app; IGxSelection selec = a.getSelection(); JOptionPane.showMessageDialog (null, selec.toString()); } But doesn’t give you anything sensible, as IGxSelection is an ArcCatalog class, and here the Application object is the ArcMap Application object, not the ArcCatalog one.

11 Interfaces In general, better to get the interface right and keep the object defined by its interfaces. As well as explicitly casting, just attaching the right label works if you are going to a less specific class: IMxDocument mxDoc = app.getDocument(); But generally in the examples you’ll see an explicit cast because it saves looking up the relationship. In the API Docs, in general go for the interface list at the top of the class. Interfaces generally start “I” Then “Mx” for ArcMap, “Gx” for ArcCatalog.

12 ArcMap IApplication methods newDocument(boolean userPickTemplate?, String path) openDocument(String optionalPath) refreshWindow() saveDocument(String optionalPath) If the paths are null, the usual “new”, “open”, and “save” processes occur.

13 ArcMap IMXDocument methods Used for getting data: getActiveView() i.e. layout view or data view data. getFocusMap() i.e. currently selected/shown map. getMaps() i.e. all maps. getSelectedItem() i.e. that the user has picked. getSelectedLayer() i.e. that the user has picked. Documents also implement IDocument, the main use of which is programmatically controlling toolbars.


Download ppt "Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document."

Similar presentations


Ads by Google