Hi, I need an easy way to split a string at a desired lengt, but I want to avoid splitting words. There once was a WordWrapper but it's not working anymore. Any suggestions?
WordWrapper 2.0?
Best answer by david_r
I posted this a long time ago, but it's not easily searchable and the code has been mangled while ported between the different versions of the forum software, so here's a slightly modified version of my original post.
You can insert the following code into a PythonCaller, it will read a string from the attribute "text_line_data" and wrap it at the position specified in a parameter "MaxWidth":
import fmeobjects
import textwrap
def TextWrapper(feature):
text = feature.getAttribute("text_line_data") # modify as necessary
maxLength = int(FME_MacroValues['MaxWidth'])
parts = textwrap.wrap(text, maxLength)
feature.setAttribute('number_of_parts', len(parts))
if parts:
feature.setAttribute('parts{}', parts)Expose the attributes "parts{}" and "number_of_parts" in the PythonCaller.
This outputs all parts to the list "parts{}", you can then use a ListExploder to get one feature per wrapped line, see attached sample workspace.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.
Login to the community
No account yet? Create an account
An FME Account is required to contribute
LoginEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.





