Multi-line text entry in Model Builder Parameter

714
10
03-10-2022 07:19 PM
Labels (2)
LindsayRaabe_FPCWA
Regular Contributor

Hi Brains Trust. I thought this was a simple thing, but I can't quite figure it out. I want to be able to enter multi-line text into a Models string parameter, but it seems to only accept single line of text. Destination will be a string field in a feature class. 

LindsayRaabe_FPCWA_0-1646968710732.png

LindsayRaabe_FPCWA_1-1646968748550.png

 

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
10 Replies
DanPatterson
MVP Esteemed Contributor

There is multivalue, but not multiline (same in modelbuilder)

Setting script tool parameters—ArcGIS Pro | Documentation

I suspect you want a "textbox" rather than a "textline" to display the full text of field entry


... sort of retired...
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

I assume text boxes are not an option?

Could a text file work in place of a text line/box?

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
Luke_Pinner
MVP Regular Contributor

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

 

unnamed.png

 

0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

Thanks for the suggestion. I've had a look at that now and don't think that's really a viable option. Would it be possible to load the text in a text file (using the Text File variable) and use a python code to extract the text and calculate field?

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

I feel like I'm getting closer - but still need guidance. I've created a Calculate Value Code Block as per below but have 2 problems (at least, 2 for now):

LindsayRaabe_FPCWA_1-1646981665049.png

LindsayRaabe_FPCWA_2-1646981743283.png

 

1. I can't figure out how to replace the written file path on line 4 with the pathway from the variable (which is a text file) i.e. path = (str_path). When I do, I get the below error. 

LindsayRaabe_FPCWA_3-1646981841268.png

2. When I run it successfully as per the original script, the output Value is still blank (at least as far as I can tell). 

LindsayRaabe_FPCWA_4-1646981919230.png

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
Luke_Pinner
MVP Regular Contributor
You don't return anything from your function.  Also, readlines() returns a list, not a string.
 
Here's a simpler version that returns a string containing the text of the file.
 
Expression:
Result(r"%Text File%")
 
Code block:
def Result(txtfile):
    return open(txtfile).read()
 
 

unnamed.png

 

You could probably even just use the following without a code block
 
Expression:
open(r"%Text File%").read()
 
 
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

Nearly worked! It did indeed calculate the Value as you suggested (just using the Expression instead of the code block) but the calculate field step failed where it encountered the new line. 

LindsayRaabe_FPCWA_0-1647304974656.png

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

Trying to fix the issue by turning the multiline text file into a single, long string. Started a new expression as per below, but the Code block keeps removing the \n and just moving the text onto a new line. 

LindsayRaabe_FPCWA_0-1647310915500.png

 becomes this:

LindsayRaabe_FPCWA_1-1647310923957.png

So I tried this too:

LindsayRaabe_FPCWA_2-1647310952453.png

but get this error:

LindsayRaabe_FPCWA_3-1647310963104.png

which is the same error I get from just running the field calculator with the original multiline text value. So frustating!

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
Luke_Pinner
MVP Regular Contributor

Leave your new lines/ carriage returns in and just wrap in triple quotes instead of single quotes in the calculate field expression.  String literals inside triple quotes, """ or ''', can span multiple lines of text.

r"""%Value%""" 

0 Kudos