New Line Character - Arcpy

4163
3
Jump to solution
09-11-2014 09:15 AM
JorgeOrellana
Occasional Contributor II

Here is my current issue, I am writting a Python script that will update my map title on a large amount of MXDs in a folder. If I hard code my text update it will work. For example if i set (hard code my text property)

elem.txt = """<FNT size="11.5">Project Title 1\r\nProject Title 2</FNT>\r\nMap of Property\r\n<dyn type= "page" property="Map_ID"/>"""

my MXDs updates with no issues

However the end result is to be able to turn my script into a Toolbox where the user can enter the updated text  as needed. However when I enter the same text into my Toolbox and run the script my MXD formatting is off. i.e. the new line character is no longer inserted.

Anyone have an idea on how I can do this in the Toolbox so it doesn't throw my formatting off?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

The problem is that parameters are usually passed in GP using a string representation so your newline is not getting across unmolested. I have run into this with the Calculate Value tool, where I have had to use chr(10) instead of  "\n".

An approach that may work would be to instruct the user to insert a normal character ("@" for example) and replace it with the real deal in Python:

title = title.replace("@", "\n")

title = title.replace("@", chr(10))

View solution in original post

3 Replies
JamesCrandall
MVP Frequent Contributor

Let's see the Toolbox code.

0 Kudos
curtvprice
MVP Esteemed Contributor

The problem is that parameters are usually passed in GP using a string representation so your newline is not getting across unmolested. I have run into this with the Calculate Value tool, where I have had to use chr(10) instead of  "\n".

An approach that may work would be to instruct the user to insert a normal character ("@" for example) and replace it with the real deal in Python:

title = title.replace("@", "\n")

title = title.replace("@", chr(10))

JorgeOrellana
Occasional Contributor II

Worked like a charm!! Thanks Curtis, it was the piece I was missing.

Cheers

0 Kudos