Multiline GPString Parameters in Python Toolbox

741
4
01-06-2023 02:06 PM
RogerDunnGIS
Occasional Contributor II

I wrote a Python Toolbox tool for ArcGIS Pro which receives a large amount of text from the user.  This could be a comment, note, or documentation.  The value of this parameter is later inserted into a very wide text field of a feature class, when the tool is run.  Note: the field is a supported field type, not a BLOB.  However, the user is unable to press Enter for a new line or paragraph, and they wish to do so.  Also, any text pasted into this parameter only gets as far as the first paragraph, stopping just shy of the carriage return.  I suppose this could be fixed if the user was presented with a memo-like control to input all this text.  Can this be done?  Can I present the user with a multi-line control to input a large comment with carriage returns?

4 Replies
JohnStreeb
Occasional Contributor

I'm not familiar enough to know personally if there is a solution exactly as you are asking for.  I do wonder however, as a work around, if it would be sufficient to add an optional input parameter of a text file.  You could have the text input as-is they can use if the text is short enough or allow them to input a basic *.txt file as an input otherwise for longer/multi-line text.  Not sure if that would really meet your needs or not, but, figured I'd at least throw it out there in case it helps.

0 Kudos
Luke_Pinner
MVP Regular Contributor

Ugly workaround - use a "SQL Expression" datatype...?

Multi-line text entry in Model Builder Parameter

 

0 Kudos
by Anonymous User
Not applicable

I was hoping that a key combo such as the Shift+Enter would work but it didn't.  You could have them separate the paragraphs with three spaces (or a combo that wouldn't be found in natural type) and then do a replace in the string and replace with /n or /n/n, depending on what spacing you want.

 

intext = arcpy.GetParameterAsText(0)
if not intext or intext == '':
    intext = 'sdffewafaewfwaefawefaewa  awefaewfawe afewaewf   aewfewafaefa aewfaewfa afwefaefae awefrerafafcaewcew   awefewafacawewsfdaesfea'

intext_updated = intext.replace('   ', '\n\n')
...

 

 

Screenshot 2023-01-06 193523.png

If you truly want a TextBox, think you'll have to go to the Pro SDK and create an Addin to get access to the WPF controls.

0 Kudos
RogerDunnGIS
Occasional Contributor II

Thank you, everyone, for your suggestions.  I'll have to ask the end users what they want as a solution.  This field's value is usually the result of selecting and copying a lot of text from a web page and pasting it into the tool.  The content of the field is always an obituary, and is usually long.  A URL wouldn't suffice because web sites get taken down, companies get purchased and their URL's change, and content can get reorganized over time.

0 Kudos