1

I am trying to modify a FeatureLayer's Maplex label settings. For some reason those properties don't get modified when opening the document afterwards. The document I am opening HAS already set the option "Use maplex label engine" property set.

def ApplyModificationsMainLayer(featureLayer):
    featureLayer.Name = "PAD"
    pGeoFeatureLayer = CType(featureLayer, esriCarto.IGeoFeatureLayer)
    pGeoFeatureLayer.DisplayAnnotation = True
    propertiesCollection = pGeoFeatureLayer.AnnotationProperties

    pLabelEngineLayerProperties = NewObj(esriCarto.MaplexLabelEngineLayerProperties, esriCarto.ILabelEngineLayerProperties2)

    pMaplexOverposter = NewObj(esriCarto.MaplexOverposterLayerProperties, esriCarto.IMaplexOverposterLayerProperties)
    pMaplexOverposter.FeatureType = 1
    pMaplexOverposter.LinePlacementMethod = 7
    pMaplexOverposter.PrimaryOffset = 10
    pMaplexOverposter.PrimaryOffsetUnit = 0
    pMaplexOverposter.CanReduceFontSize = True
    pOverposter = CType(pMaplexOverposter, esriCarto.IOverposterLayerProperties)
    pLabelEngineLayerProperties.OverposterLayerProperties = pOverposter

    pLabelEngineLayerProperties.Expression = "[Length]"
    pLabelEngineLayerProperties.Symbol.Size = 7




    propertiesCollection.Clear()
    propertiesCollection.Add(pLabelEngineLayerProperties)
    #cast to ILayer before saving
    pLayer = CType(pGeoFeatureLayer, esriCarto.ILayer)
    return pLayer

I have tried to get a reference of the "Default" Label Class and it seems that when I try to cast it's OverposterLayerProperties to IMaplexOverposterLayerProperties it returns a Null Type Pointer.

Why would this happen ?

  • Are you saving your MXD? Is this ArcObjects in python? Can you try this in an active ArcMap session and see if the settings are being applied there? – Michael Stimson Apr 16 '18 at 5:18
  • Yes, this is ArcObjects in Python. I do have a template.mxd which I am saving with MapDocument.SaveAs() function. I have already opened the "saved" document and it also has the "Use Maplex Label Engine" set also. – Damian Radinoiu Apr 16 '18 at 5:25
  • The only thing I can see at a glance is that IGeoFeatureLayer doesn't implement ILayer, try pLayer = CType(featurelayer, esriCarto.ILayer), the properties should already be updated on the IFeatureLayer. – Michael Stimson Apr 16 '18 at 5:30
  • It doesn't work either. By the way this code used to work perfectly when I was using Standard Label Engine – Damian Radinoiu Apr 16 '18 at 5:45
  • I have tried to get a reference of the "Default" Label Class and it seems that when I try to cast it's OverposterLayerProperties to IMaplexOverposterLayerProperties it returns a Null Type Pointer. Why would this happen ? – Damian Radinoiu Apr 16 '18 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.