Hi there,
how can I write an add-in that shows a Message Box when the project is loaded? I want to give the user some new informations, when he starts a new project?
Thanks,
Karsten
Hi,
You can subscribe to the ProjectOpenedEvent (topic9319) to accomplish this. Additionally, the add-in will need to load as soon as Pro launches, so you will have to set the "autoload" attribute to true in the config.daml of the add-in. Code snippets below:
In the Module class of the add-in:
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">bool</SPAN> <SPAN class="token function">Initialize</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ProjectOpenedEvent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Subscribe</SPAN><SPAN class="punctuation token">(</SPAN>OnProjectOpened<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//subscribe to event</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">base</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Initialize</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnProjectOpened</SPAN><SPAN class="punctuation token">(</SPAN>ProjectEventArgs obj<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>$<SPAN class="string token">"{Project.Current} has opened"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//show your message box</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">Uninitialize</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ProjectOpenedEvent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Unsubscribe</SPAN><SPAN class="punctuation token">(</SPAN>OnProjectOpened<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//unsubscribe</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
In your config.daml, set the autoload attribute to true so that the add-in loads when Pro launches:
... <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>modules</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>insertModule</SPAN> <SPAN class="attr-name token">id</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>SubscribeProjectLoad_Module<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">className</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Module1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">autoLoad</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>true<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">caption</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Module1<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> ...<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks
Uma
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.