Select to view content in your preferred language

Multi-line text entry in Model Builder Parameter

2469
11
03-10-2022 07:19 PM
Labels (2)
LindsayRaabe_FPCWA
Regular Contributor II

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
11 Replies
LindsayRaabe_FPCWA
Regular Contributor II

Thanks for the tip. I tried that in the Code Block and it still moved the following text to a new line....so I decided to try something else. I've created a python script with the function in it loaded as a script in my Toolbox and model with an input parameter (the path to my .txt file) and an output parameter (the new single-line string). I can get it to run the function successfully, removing "\n" and replacing it with "", and I WAS struggling to get the value out as a parameter I can feed into another model step, but have just discovered I had called the function result incorrectly.

Here's my methodology to get the text file input to a value I can use in Field Calculator:

LindsayRaabe_FPCWA_0-1647325447290.png

And the code as a sample:

import re
import arcpy

inFile = open(arcpy.GetParameterAsText(0)).read()

def Result(Value):
        inValue = Value
        newValue = inValue.replace("\n", "")
        re.sub('\s{2,}', ' ', inValue) # To remove more than one space
        #print (newValue)
        return newValue
        
outText = Result(inFile)
arcpy.AddMessage(outText)
#print(outText)
arcpy.SetParameterAsText(1, outText)

 

A big thank you to @Luke_Pinner for your pointers. I would not have got this far without them. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
PhilLarkin1
Regular Contributor

This might help others who are at Pro 3.1

https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/parameter-controls.htm

PhilLarkin1_0-1700531265807.png

 

# set self.params for use in other function
self.params = arcpy.GetParameterInfo()
# Multiline block of text
self.params[1].controlCLSID = '{E5456E51-0C41-4797-9EE4-5269820C6F0E}'