2

Let's say, a road has the name "William-Bill-Gates-Road".

If the road is too short, the label can only be abbreviated by using a dictionary in Maplex. Is it possible to make Maplex try several label fields, if one is not fitting?

Structure:

name | name_1 | name_2 | ... William-Bill-Gates-Road | William-Bill-Gates-Rd. | W.-Bill-Gates-Rd. | W.-B.-Gates-Rd.

1

1 Answer 1

1

The short answer is yes.
here is some code that should work in 10.0 and previous.
Grant it doesn't exactly use an alternate field but shortens the word.
I figure you might be able to recreate it with the loop you need.

Function FindLabel ( [Name] )

Dim strArray
Dim outStr
Dim x
Dim maxWordLength
Dim minLengthLength
Dim everyother
Dim isFirst
Dim lastWordLong
lastWordLong = false

maxWordLength = 10
minWordLength = 3
everyother = False
isFirst = True
strArray = Split( [Name], " ")

For x = 0 To UBound(strArray)

    If ((Not isFirst) And (Len(strArray(x)) <= minWordLength)) Then
        'keep short word on existing line
        outStr = outStr & " " & strArray(x)
        everyother = False
    ElseIf (everyother) Then
        'word x is slated to be second word on line
        If (Len(strArray(x)) > maxWordLength) Then
            outStr = outStr & vbNewLine & strArray(x)
            everyother = False
        Else
            outStr = outStr & " " & strArray(x)
            everyother = False
        End If
    Else
        'word x is slated to be first word on line
        If (isFirst) Then
            outStr = strArray(x)
            everyother = True
            isFirst = False
        Else
            If (Len(strArray(x)) > maxWordLength) Then
                lastWordLong = True
                everyother = False
            Else
                lastWordLong = False
                everyother = True
            End If

            outStr = outStr & vbNewLine & strArray(x)

        End If
    End If
Next

FindLabel = outStr
End Function

I didn't write it but inherited a map with that vbscript in it.

1
  • Thanks for the code, but the problem is, the function will run even if there's enough space on the geometry to label the full name. By using "keywords" in the dictionary of Maplex, it tries the normal name first and then looks for a fitting abbreviation. Commented Sep 29, 2012 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.