how to obtain ILabelEngineLayerProperties2 ?  and error calling it's method

1719
5
Jump to solution
06-27-2014 12:46 AM
SeanNakasone
New Contributor II
How do we obtain ILabelEngineLayerProperties2 ?

The only way I could figure it out is through IGeoFeatureLayer.AnnotationProperties which is collection of IAnnotateLayerProperties interfaces.  Then I cast IAnnotateLayerProperties to ILabelEngineLayerProperties2 .

I think this is working for me, but I'm not 100% sure as I'm getting the following error calling
ILabelEngineLayerProperties2.BasicOverposterLayerProperties .

System.NotImplementedException: The method or operation is not implemented.
   at ESRI.ArcGIS.Carto.ILabelEngineLayerProperties2.get_BasicOverposterLayerProperties()

suggestions?
0 Kudos
1 Solution

Accepted Solutions
RobertMaddox
New Contributor III
I honestly have no idea what Maplex is either. [I'm really more of a programmer than a gis person. ;)] From looking at the docs though, it doesn't look like it requires any special extensions.

Try taking your test code a little further though:
ILabelEngineLayerProperties2 test = labEngLyrProp as ILabelEngineLayerProperties2; if(test == null) {     Console.WriteLine("NOT an ILabelEngineLayerProperties2"); } else {     Console.WriteLine("IS an ILabelEngineLayerProperties2");     IOverposterLayerProperties olp = test.OverposterLayerProperties;     if (olp is IMaplexOverposterLayerProperties) {         Console.WriteLine("olp is IMaplexOverposterLayerProperties");     } else if (olp is IBasicOverposterLayerProperties) {         Console.WriteLine("olp is IBasicOverposterLayerProperties);     } else {         Console.WriteLine("olp is an unknown type!");     } }


Running that should be able to tell you what's going on. 😉

View solution in original post

0 Kudos
5 Replies
RobertMaddox
New Contributor III
It looks like there might be types in there that don't implement that interface. So I would suggest testing to see if the object you are getting is of that type before casting it. The best way I find is to use the conditional casting operator, like so (assuming you're in a for loop):


//C#
ILabelEngineLayerProperties2 lelp = alp as ILabelEngineLayerProperties2;
if (lelp == null) continue;



'VB.NET
Dim lelp as ILabelEngineLayerProperties2 = TryCast(alp, ILabelEngineLayerProperties2)
If lelp Is Nothing Then Continue For


Another possibility is that the object might implement the interface, but not that property. I really doubt this would be the case as I haven't encountered this type of thing in ArcObjects before and because the docs basically say that this property is why this interface exists.
*Looks at Documentation again...*

*facepalm* Scratch that. Should have known better than to under estimate ESRI's ability to screw up their API and documentation. The documentation for the ILabelEngineLayerProperties interface (but not on the ILabelEngineLayerProperties2 interface!) states the following:
ILabelEngineLayerProperties::BasicOverposterProperties is not implemented by MaplexLabelEngineLayerProperties.  See ILabelEngineLayerProperties2 for methods for generic handling of labeling properties for both label engines.

That means that if any of your layers are using the Maplex Label Engine, then you will get this error when calling ILabelEngineLayerProperties2.BasicOverposterLayerProperties. I don't know why they didn't mark the BasicOverposterLayerProperties property as deprecated if they were going to introduce a breaking change like this...

So what you need to do is use the ILabelEngineLayerProperties2 .OverposterLayerProperties property. If the IOverposterLayerProperties interface doesn't have the things you need, then you'll have to cast them to their more specific interfaces in separate code blocks like so:


//C#
IOverposterLayerProperties olp = lelp.OverposterLayerProperties;
IBasicOverposterLayerProperties bolp = olp as IBasicOverposterLayerProperties;
IMaplexOverposterLayerProperties molp = olp as IMaplexOverposterLayerProperties;
if (bolp != null)
{
    //Do something here with bolp
}
else if (molp != null)
{
    //Do something here with molp
}


I'll skip the VB.NET version this time. I'm pretty sure you can translate that at this point.

Hope this helps you and anyone else who runs into this issue. 😉
0 Kudos
SeanNakasone
New Contributor II
Thanks for the info Robby.

The object is ILabelEngineLayerProperties2, because the following code is outputting "IS an ILabelEngineLayerProperties2".

ILabelEngineLayerProperties2 test = labEngLyrProp as ILabelEngineLayerProperties2;
if(test == null) {
   Console.WriteLine("NOT an ILabelEngineLayerProperties2");
} else {
   Console.WriteLine("IS an ILabelEngineLayerProperties2");
}

I really doubt we are using Maplex, because isn't that an ArcGIS extension?  We didn't purchase any extensions yet.  If it's possible to use Maplex w/o purchasing it, how can we check if we are using it?
0 Kudos
RobertMaddox
New Contributor III
I honestly have no idea what Maplex is either. [I'm really more of a programmer than a gis person. ;)] From looking at the docs though, it doesn't look like it requires any special extensions.

Try taking your test code a little further though:
ILabelEngineLayerProperties2 test = labEngLyrProp as ILabelEngineLayerProperties2; if(test == null) {     Console.WriteLine("NOT an ILabelEngineLayerProperties2"); } else {     Console.WriteLine("IS an ILabelEngineLayerProperties2");     IOverposterLayerProperties olp = test.OverposterLayerProperties;     if (olp is IMaplexOverposterLayerProperties) {         Console.WriteLine("olp is IMaplexOverposterLayerProperties");     } else if (olp is IBasicOverposterLayerProperties) {         Console.WriteLine("olp is IBasicOverposterLayerProperties);     } else {         Console.WriteLine("olp is an unknown type!");     } }


Running that should be able to tell you what's going on. 😉

View solution in original post

0 Kudos
SeanNakasone
New Contributor II
It's returning...

"olp is IMaplexOverposterLayerProperties"

I didn't expect this.  Thank you very much.
0 Kudos
RobertMaddox
New Contributor III
Glad I could help. 😉
0 Kudos