| This post was last edited by sishui198 Http://bbs.esrichina-bj.cn/esri/viewthread.php? Tid = 105152 & extra = Page % 3d1% 26amp % 3 bfilter % 3 ddigest com Customization Http://bbs.esrichina-bj.cn/esri/viewthread.php? Tid = 105114 & extra = Page % 3d1% 26amp % 3 bfilter % 3 ddigest add-in Mode
In the previous two posts, we introduced the COM and add-in methods for customized desktop development, and made everyone feel through two identical functions, add-in is a new technology, and we recommend that you use add-in instead of the previous com purchase method. in this article, we will discuss migration. Migration is common and confusing for programmers (in fact, I don't have a programmer's certificate), but please relax this time, because it is very easy to migrate from com to add-in, and there are very few changes to the code! Let me start from the following aspects: L command interface display icon, category, name L whether the command is available L association between commands and operation objects L Event Response Below we will introduce these aspects: L command interface display icon, category, name The COM interface display is related statements in the constructor, as follows: Download(29.96 KB) For the add-in method, we know that when we select a template, the information is written in the XML file, and the code and interface are separated, this makes our logic clearer ., for example: Download(174.36 KB) L whether the command is available In the com mode, we can override the Enable attribute. This attribute is automatically called every 500 milliseconds. You can rewrite the enabled attribute for us. It is available if the number of layers is greater than 0. Download(14.84 KB)
For the add-in method, we write it directly in the update function. add-in directly exposes the Enable attribute to us, so we do not need to inherit it, which is very convenient, as shown below: Download(5.25 KB) L association between commands and operation objects In the com method, there is an oncreate function. This function is called by the system after the constructor is called, and a hook is passed in. This hook is the object to be used by the command, therefore, whether this command can act on this object depends on whether it can be associated with the hook. If we create a command for ArcMAP, the hook is ArcMap. Download(15.53 KB) In add-in, the oncreate function does not exist, so how is it associated? When selecting the add-in template, for example, selecting ArcMAP, the wizard automatically generates a static ArcMap class for us. This static class encapsulates many interfaces, through this static class, we can do whatever we want. That is to say, this static class allows us to obtain the entry of the relevant object. The following is the static class code of ArcMap: Download(21.35 KB) In the constructor, we can directly use this object to obtain relevant information, as shown below:
- Imxdocument pmxd;
- Public arcmapbuttonaddin ()
- {
- Pmxd = ArcMap. Document as imxdocument;
- }
Copy code L Event Response The responses to events are almost identical. In the com mode, the following functions are used for commands:
Download(6.51 KB) In add-in, there is the following. Is there any difference? Download(6.08 KB)
We basically talked about migration. Through this example, we can see that the add-in code is less? How is it? |