<?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: Problem copying layer file (.lyr) to a different location in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299193#M7780</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you thought about just creating a layer package or a map package if you're using ArcGIS 10?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.esri.com/library/fliers/pdfs/easy-ways-share-data.pdf"&gt;http://www.esri.com/library/fliers/pdfs/easy-ways-share-data.pdf&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Jul 2011 12:36:56 GMT</pubDate>
    <dc:creator>NeilClemmons</dc:creator>
    <dc:date>2011-07-19T12:36:56Z</dc:date>
    <item>
      <title>Problem copying layer file (.lyr) to a different location</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299192#M7779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have written some code which exports a feature class in the TOC to a shapefile and a layer file. However when I copy the output results to a different location it seems the layer file's data source is still looking at the original location. The shapefile changes its data source to the new location but the layer file doesn't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I am looking to do is run my code, get the shapefile and layer file outputs and pass them to work mates. There are hundreds of outputs so I would like to automate this process. But as it stands my work mates would have to manually repair the data source for each and every broken layer file I give them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect it might be an issue regarding relative path names or resetting the data source of the layer file but I'm just not sure how to go about either option as I am new to VBA and learning as I go.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code so far is ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'Create layer file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pGxLayer As IGxLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pGxfile As IGxFile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxLayer = New GxLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxfile = pGxLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pGxfile.Path = "D:\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxLayer.layer = pMap.layer(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxfile = Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxLayer = Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'Set data source of layer file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxLayer = New GxLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxfile = pGxLayer&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pDLayer As IDataLayer2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pDLayer = pGxLayer.Layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pDSName As IDatasetName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pDSName = pDLayer.DataSourceName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Debug.Print "old path : " &amp;amp; pDSName.WorkspaceName.PathName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pWSName As IWorkspaceName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pWSName = pDSName.WorkspaceName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pWSName.PathName = 'I'm not sure what to put here I've tried &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Debug.Print "new path: " &amp;amp; pDSName.WorkspaceName.PathName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pDLayer.DataSourceName = pDSName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pGxLayer.Layer = pDLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pGxfile.Save&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the new path name or to set the path name to relative I'm not sure what to put in ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;".\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And neither of these works ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated. Thanks so much.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;m&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 04:14:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299192#M7779</guid>
      <dc:creator>MPickering</dc:creator>
      <dc:date>2011-07-19T04:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem copying layer file (.lyr) to a different location</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299193#M7780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you thought about just creating a layer package or a map package if you're using ArcGIS 10?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.esri.com/library/fliers/pdfs/easy-ways-share-data.pdf"&gt;http://www.esri.com/library/fliers/pdfs/easy-ways-share-data.pdf&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 12:36:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299193#M7780</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2011-07-19T12:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem copying layer file (.lyr) to a different location</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299194#M7781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately I'm using 9.3.1. I see you can manually export to a layer package in 9.3.1. Do you know if you can use vba or python to export out as a layer package?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;m&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 22:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299194#M7781</guid>
      <dc:creator>MPickering</dc:creator>
      <dc:date>2011-07-19T22:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem copying layer file (.lyr) to a different location</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299195#M7782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't think there is any direct support in the ArcObjects model but you should be able to execute the context menu's command item.&amp;nbsp; Just set the document's context item prior to executing it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Sub CreateLayerPackage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim uid As New uid
&amp;nbsp;&amp;nbsp;&amp;nbsp; uid.Value = "{18DF94D9-0F8A-11D2-94B1-080009EEBECB}:23"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim mxDoc As IMxDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set mxDoc = ThisDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxDoc.ContextItem = mxDoc.FocusMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim commandItem As ICommandItem
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set commandItem = ThisDocument.CommandBars.Find(uid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; commandItem.Execute
End Sub
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:21:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-copying-layer-file-lyr-to-a-different/m-p/299195#M7782</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2021-12-11T14:21:58Z</dc:date>
    </item>
  </channel>
</rss>

