def FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ): name = " ".join(str( [DEEDHOLDER] ).split(" ")[:5]) # grab only first few words on top line name2 = " ".join(str( [DEEDHOLDER] ).split(" ")[5:]) # grab the rest if there are more to wrap to next line if len(name2) > 1: name = "\n".join([name,name2]) # join name and name2 vars by a new line pid = [PID] ac = [ACRES] + " Ac" sump = "CSR: "+ str(round(float([SUM_CSR_Potential]),1)) ave = "Ave: "+ [AVE_CSR] return "\n".join([name,pid,ac,sump,ave])
Solved! Go to Solution.
First off, I'll admit I do not know much about VB. A while back I found that there is a bug with exporting maps that have "advanced" python expressions to PDF programmatically (i.e. doing this through arcpy.mapping). This is not a problem when using VB label expressions. I have been trying (and failing) to convert the following Python label expression to VB. This works inside ArcMap but the labels disappear when exported to PDF due to the bug.def FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ): name = " ".join(str( [DEEDHOLDER] ).split(" ")[:5]) # grab only first few words on top line name2 = " ".join(str( [DEEDHOLDER] ).split(" ")[5:]) # grab the rest if there are more to wrap to next line if len(name2) > 1: name = "\n".join([name,name2]) # join name and name2 vars by a new line pid = [PID] ac = [ACRES] + " Ac" sump = "CSR: "+ str(round(float([SUM_CSR_Potential]),1)) ave = "Ave: "+ [AVE_CSR] return "\n".join([name,pid,ac,sump,ave])
This isn't too complicated in Python, but I am unable to successfully convert it to VB. I would post my attempts at a VB solution, but I would rather save myself the embarrassment.
If anyone can help, I would appreciate it! Meanwhile, I will keep trying.
Function FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ) Dim MyArray, i, name, pid, ac, sump, ave MyArray = Split([DEEDHOLDER], " ") For i = 0 to UBound(MyArray) if i = 0 Then name = MyArray(i) ' First word of name. ElseIf i / 5 <> Round(i / 5, 0) Then name = name & " " & MyArray(i) ' Add space and word if less than 5 words in line Else name = name & vbCrLf & MyArray(i) ' Begin a new line after every 5th word. End If Next pid = [PID] ac = [ACRES] & " Ac" sump = "CSR: " & str(round(cDbl([SUM_CSR_Potential]),1)) ave = "Ave: " & [AVE_CSR] FindLabel = name & vbCrLf & pid & vbCrLf & ac & vbCrLf & sump & vbCrLf & ave End Function
First off, I'll admit I do not know much about VB. A while back I found that there is a bug with exporting maps that have "advanced" python expressions to PDF programmatically (i.e. doing this through arcpy.mapping). This is not a problem when using VB label expressions. I have been trying (and failing) to convert the following Python label expression to VB. This works inside ArcMap but the labels disappear when exported to PDF due to the bug.def FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ): name = " ".join(str( [DEEDHOLDER] ).split(" ")[:5]) # grab only first few words on top line name2 = " ".join(str( [DEEDHOLDER] ).split(" ")[5:]) # grab the rest if there are more to wrap to next line if len(name2) > 1: name = "\n".join([name,name2]) # join name and name2 vars by a new line pid = [PID] ac = [ACRES] + " Ac" sump = "CSR: "+ str(round(float([SUM_CSR_Potential]),1)) ave = "Ave: "+ [AVE_CSR] return "\n".join([name,pid,ac,sump,ave])
This isn't too complicated in Python, but I am unable to successfully convert it to VB. I would post my attempts at a VB solution, but I would rather save myself the embarrassment.
If anyone can help, I would appreciate it! Meanwhile, I will keep trying.
Function FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ) Dim MyArray, i, name, pid, ac, sump, ave MyArray = Split([DEEDHOLDER], " ") For i = 0 to UBound(MyArray) if i = 0 Then name = MyArray(i) ' First word of name. ElseIf i / 5 <> Round(i / 5, 0) Then name = name & " " & MyArray(i) ' Add space and word if less than 5 words in line Else name = name & vbCrLf & MyArray(i) ' Begin a new line after every 5th word. End If Next pid = [PID] ac = [ACRES] & " Ac" sump = "CSR: " & str(round(cDbl([SUM_CSR_Potential]),1)) ave = "Ave: " & [AVE_CSR] FindLabel = name & vbCrLf & pid & vbCrLf & ac & vbCrLf & sump & vbCrLf & ave End Function
Function FindLabel ( [DEEDHOLDER] , [PID], [ACRES], [SUM_CSR_Potential], [AVE_CSR] ) Dim MyArray, i, name, pid, ac, sump, ave MyArray = Split([DEEDHOLDER], " ") For i = 0 to UBound(MyArray) if i = 0 Then name = MyArray(i) ' First word of name. ElseIf i / 5 <> Round(i / 5, 0) Then name = name & " " & MyArray(i) ' Add space and word if less than 5 words in line Else name = name & vbCrLf & MyArray(i) ' Begin a new line after every 5th word. End If Next pid = [PID] ac = [ACRES] & " Ac" sump = "CSR: " & CStr(Round(CSng([SUM_CSR_Potential]),1)) ave = "Ave: " & CStr(Round(CSng([AVE_CSR]),1)) FindLabel = name & vbCrLf & pid & vbCrLf & ac & vbCrLf & sump & vbCrLf & ave End Function
Hi guys, ran into this problem yesterday. Is there any other way besides converting to VB expressions?
Cheers
from textwrap import fill def FindLabel([LEGAL1]): x = fill([LEGAL1],18) return x
Function FindLabel ( [LEGAL1] ) ' Stacks a label in multiple lines if ' exceeding a given length. ' Note: Not applicable to line layers. ' ------------------------------------ dim s, sNew, i, l s = [LEGAL1] l = Len(s) if l > 15 then ' stack if exceeding this length sNew = Left(s,15) i = 16 ' scan for blank space starting from this position While i <= l 'or: Do While if Mid(s,i,1) = " " then 'added: & Mid(s,i,15) sNew = sNew & VBNewLine & Mid(s,i,15) 'added the following to "skip" i to the next segment i = i + 15 else sNew = sNew & Mid(s,i,1) 'moved the below line inside "end if" i = i + 1 end if Wend 'or, coupled with the above "Do While": Loop else sNew = s end if FindLabel = sNew End Function
Here is the nimbus for the support incident I logged with Esri regarding the issue:
NIM091502: Labels written in advanced python are not displayed when exported to PDF outside of ArcMap.
Just to echo what Richard already said, I think VB may be the best option if you are exporting PDF's programmatically. I have had successful exports with some 'advanced python' expressions I have tried, but VB never fails.