[GIS] Inline variable substitution in Model Builder using python code

arcgis-desktoparcpymodelbuilderparameterspython

I have an inline variable substiution which I would like to import into my Python script. Is that possible? I am trying to make a parameter within my path.

My path currently is "c:\Users\Jelle\Dropbox". Within Model Builder I can substitute 'Jelle' by using an inline variable subsitution (name) and call it through %name%.
I would like to replace "Jelle" with other names but then within a Python script.

I have tried using GetParameterAsText and making the inline variable as a Parameter within Model Builder but I get an empty output: Here is the script which I tried for it:

import arcpy
username = arcpy.GetParameterAsText(0) #this is the inline variable 'name' which I am trying to call
input_table = "C:\\Users\\"+str(username)+"\\Dropbox"

Input_table gives the following return:

"C:\Users\\Dropbox"

Hence the 'username' variable is not returned

I have the feeling I should be using something else other than GetParameterAsText. Could someone help me out here?

Best Answer

you can use your inline variable directly in the calculateField tool.

with a Python expression entered in the CalculateField tool, it would look like this:

"C:\\Users\\{}\\Dropbox".format(%name%)

The variable should be present in your model (right clic > create variable > Type = String). Here I renamed it "Name" and required it as a precondition, but this should not be necessary. Check this variable as a model parameter if you want users of the model to modify it from the form.

enter image description here