<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Button add-in problem (VB) in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287649#M7460</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again, Ken, but it's still not working.&amp;nbsp; I'm not going to waste anymore time with this snippet.&amp;nbsp; I've tried other snippets and I didn't have any problems.&amp;nbsp; Maybe I'm missing a Reference, or something, to get this one to work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Jun 2012 17:38:02 GMT</pubDate>
    <dc:creator>DaveCouture</dc:creator>
    <dc:date>2012-06-15T17:38:02Z</dc:date>
    <item>
      <title>Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287643#M7454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just had VS2010 installed with ArcGIS 10.&amp;nbsp; I???m trying to learn how the snippet works and I'm using the &lt;/SPAN&gt;&lt;STRONG&gt;AddLayerToActiveView&lt;/STRONG&gt;&lt;SPAN&gt; snippet, as a test subject. I seem to have problems invoking it, in a button.&amp;nbsp; What am I doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.Catalog Imports ESRI.ArcGIS.Carto Namespace CustomUIElements &amp;nbsp;&amp;nbsp;&amp;nbsp; Public Class AddLayer &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits ESRI.ArcGIS.Desktop.AddIns.Button&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub New()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Protected Overrides Sub OnClick()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHAT SHOULD I PUT HERE????&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.ArcMap.Application.CurrentTool = Nothing &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Protected Overrides Sub OnUpdate() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enabled = My.ArcMap.Application IsNot Nothing &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub AddLayerToActiveView(ByVal activeView As IActiveView, ByVal layerPathFile As System.String)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If activeView Is Nothing OrElse layerPathFile Is Nothing OrElse (Not layerPathFile.EndsWith(".lyr")) Then&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Create a new GxLayer &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim gxLayer As IGxLayer = New GxLayerClass&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim gxFile As IGxFile = CType(gxLayer, IGxFile) 'Explicit Cast&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Set the path for where the layerfile is located on disk &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gxFile.Path = layerPathFile&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Test if we have a valid layer and add it to the map &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Not (gxLayer.Layer Is Nothing) Then&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim map As IMap = activeView.FocusMap &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.AddLayer(gxLayer.Layer)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; End Class&amp;nbsp; End Namespace&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 15:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287643#M7454</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-15T15:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287644#M7455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-family:monospace;"&gt; &lt;/SPAN&gt;WHAT SHOULD I PUT HERE????&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AddLayerToActiveView(ByVal activeView As IActiveView, ByVal layerPathFile As System.String)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 15:15:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287644#M7455</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-06-15T15:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287645#M7456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply, Leo, but I have already tried that and I get the following error: &lt;/SPAN&gt;&lt;STRONG&gt;error BC30201: Expression expected&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think my problem is getting the active view to work, in the first argument.&amp;nbsp; I'm not sure what to put there, but I know the second argument should be the path of the layer file: &lt;/SPAN&gt;&lt;STRONG&gt;AddLayerToActiveView(????, "D:\Contours.lyr")&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 15:19:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287645#M7456</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-15T15:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287646#M7457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can use&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AddLayerToActiveView(My.ArcMap.Document.ActiveView, "D:\Contours.lyr")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 16:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287646#M7457</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2012-06-15T16:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287647#M7458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Ken, that took care of the errors.&amp;nbsp; However, when I click the button, nothing happen and the button turns grey (disabled), after clicking on it.&amp;nbsp; Any thoughts?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 16:51:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287647#M7458</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-15T16:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287648#M7459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After you add the layer to the map, you'll have to refresh the active view.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My.ArcMap.Document.ActiveView.Refresh()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The button is getting disabled because My.ArcMap.Application is being evaluated as nothing. Why? I'm not sure. This probably leads to the question of why the button isn't disabled when you start the application. With Add-ins, you have to set the onDemand tag in the config.esriaddinx to False to make the Enabled state of the button work upon startup. See &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Advanced_add_in_concepts/0001000004n7000000/" rel="nofollow" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt; for more information about delayed loading.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 17:18:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287648#M7459</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2012-06-15T17:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287649#M7460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again, Ken, but it's still not working.&amp;nbsp; I'm not going to waste anymore time with this snippet.&amp;nbsp; I've tried other snippets and I didn't have any problems.&amp;nbsp; Maybe I'm missing a Reference, or something, to get this one to work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 17:38:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287649#M7460</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-15T17:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Button add-in problem (VB)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287650#M7461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dave,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/00010000031r000000.htm"&gt;http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/00010000031r000000.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2012 18:29:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-add-in-problem-vb/m-p/287650#M7461</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-06-15T18:29:19Z</dc:date>
    </item>
  </channel>
</rss>

