Right now we have a lot of mxds with grouplayers (even som grouplayers with grouplayers).
If I import a .lyr file in ArcMap all layerids will be -1.
I'm trying to set the Layer Id for an ILayer in an mxd document but cannot find any ArcObjects interfaces exposing this property.
ILayerDescriptions needs server objects.
Any help is appreciated.
Solved! Go to Solution.
For now you can follow these steps
- you need to loop thru each extension of a layer
- QI to IServerLayerExtension
- if succeeded, you get hold of a PropertySet object using ServerProperties
- then get/set value to the key named ‘ServiceLayerID’
For now you cannot enable ‘allow assignment of unique numeric IDs for map service publishing’ programmatically
it is on a private interface. Esri peraphs adds it in 10.4 but not sure
IMapDocument mapDocument = new MapDocumentClass();
mapDocument.Open("C:\\Temp\\MyProject.mxd");
IMap b = mapDocument.get_Map(0);
ILayerExtensions c = b.get_Layer(0) as ILayerExtensions;
IServerLayerExtension g = c.get_Extension(0) as IServerLayerExtension;
IPropertySet psN = new PropertySet();
psN.SetProperty("ServiceLayerID", 8);
g.ServerProperties = psN;
mapDocument.Save();
For table
IMapDocument mapDocument = new MapDocumentClass();
mapDocument.Open(@"C:\\Temp\\MyProject.mxd");
IMap b = mapDocument.get_Map(0);
IStandaloneTableCollection c = b as IStandaloneTableCollection;
ITableExtensions d = c.get_StandaloneTable(0) as ITableExtensions;
IServerLayerExtension g = d.get_Extension(0) as IServerLayerExtension;
IPropertySet psN = new PropertySet();
psN.SetProperty("ServiceTableID", 8);
g.ServerProperties = psN;
mapDocument.Save();
You can't set Layer ID. It is pre-determined by the order of the layers in the document, and represents the layer's position in the TOC.
Maintaining a unique reference to a layer always used to be a challenge for this reason, as if you insert a layer, then the layer ID of other layers could change. The layer name is not guaranteed unique either, as you can have several layers in an mxd all with the same name. Your best option used to be to hold onto a Layer object itself, "heavyweight" though that might be, although that of course depends on what you're actually trying to achieve.
As of ArcGIS v10.3 you can assign unique numeric IDs for map service publishing.
1. Right click the data frame (default:Layers) in the TOC of ArcMap
2. On the 'General' pane you can check 'Allow assignment of unique numeric IDs for map service publishing'. This will make the a property available for each layer in your map. Please see attached screendump in the 1st post.
In the Layer property window you can actually assign an ID that should not change even if you change the order or add new layers. Totally new epic functionality.
Any help on locating the API entry for changing the Layer ID is still appreciated
Ah - I hadn't been aware of that new functionality. A good introduction!
So is it ILayerDescriptor (as opposed to ILayerDescription) that you need then?
ArcObjects Help for .NET developers
You can get an array of LayerDescriptors from a dataframe using IMapDescriptor interface.
ArcObjects Help for .NET developers
You can get an array of MapDescriptors (one for each dataframe) from the map using the IMxdServer interface.
ArcObjects Help for .NET developers
(Or you can get LayerDescriptors for the whole map from the IMxdServer interface directly)
And to get a reference to an IMxdServer interface (which shouldn't require ArcGIS for Server), it looks like you can use IMxdServer.Start:
ArcObjects Help for .NET developers
Does that work?
All changes made in MxdServer will only be in that context and will not change the property for the layers in the mxd.
Did you finally find a way to set this layer id ?
Unfortunately no.
Still working on it.
If I solve it, I will post the solution.
For now you can follow these steps
- you need to loop thru each extension of a layer
- QI to IServerLayerExtension
- if succeeded, you get hold of a PropertySet object using ServerProperties
- then get/set value to the key named ‘ServiceLayerID’
For now you cannot enable ‘allow assignment of unique numeric IDs for map service publishing’ programmatically
it is on a private interface. Esri peraphs adds it in 10.4 but not sure
IMapDocument mapDocument = new MapDocumentClass();
mapDocument.Open("C:\\Temp\\MyProject.mxd");
IMap b = mapDocument.get_Map(0);
ILayerExtensions c = b.get_Layer(0) as ILayerExtensions;
IServerLayerExtension g = c.get_Extension(0) as IServerLayerExtension;
IPropertySet psN = new PropertySet();
psN.SetProperty("ServiceLayerID", 8);
g.ServerProperties = psN;
mapDocument.Save();
For table
IMapDocument mapDocument = new MapDocumentClass();
mapDocument.Open(@"C:\\Temp\\MyProject.mxd");
IMap b = mapDocument.get_Map(0);
IStandaloneTableCollection c = b as IStandaloneTableCollection;
ITableExtensions d = c.get_StandaloneTable(0) as ITableExtensions;
IServerLayerExtension g = d.get_Extension(0) as IServerLayerExtension;
IPropertySet psN = new PropertySet();
psN.SetProperty("ServiceTableID", 8);
g.ServerProperties = psN;
mapDocument.Save();
That did the trick. 90% done.
Just need to take care of my layers not having any ILayerExtensions.
Fixed it by just creating one and adding it to the layer.
Seems that sublayers (of the annotationclasses) of IAnnotationLayers are not part of IMap get_layers enumerator. But that's a different story.
Thank you.
Hi Michael,
I encountered the same issue you are describing, while I'm programmatically updating IDs of Mxd Layers using ArcObjects 10.3.1:
- I cannot set ID for Annotation sub Layers
- this happens because IAnnotationSubLayer (s) does not implement ILayerExtentions Interface
Can you provide more details on how you solved the problem?
I'm referring to:
"Just need to take care of my layers not having any ILayerExtensions.
Fixed it by just creating one and adding it to the layer. "
Thanks a lot for any explanation.
Alessandro