Select to view content in your preferred language

Text Expression substitution with Python

4037
4
03-04-2015 09:30 AM
MikeSullivan
Regular Contributor

I am trying to create a text expression for a new custom dimension style that will label as follows from a CustomLength value and a user input as a part of the expression.  For example, "Bore Drill #<user input> ([CustomLength]')", or "Bore Drill #1 (200')" as the string.  My main problem is figuring out the python code to allow user input of the Drill # value and plug it into the rest of the string.  Any ideas?

Tags (2)
0 Kudos
4 Replies
DarrenWiens2
MVP Alum

If you're running inside ArcGIS as a script tool, you would generally collect user input with arcpy.GetParameterAsText().

myParameter1 = arcpy.GetParameterAsText(0)
myParameter2 = arcpy.GetParameterAsText(1)

^ values are now in python variables myParameter1 and myParameter2.

If you're creating a standalone script, you can also use the built-in raw_input() function.

myParameter1 = raw_input('Blahblah:  ')

^ pops up input box and collects entered text.

0 Kudos
MikeSullivan
Regular Contributor

I guess I should mention, that the text expression I'm trying to build is sort of like a calculation script.  I'm not a programmer and don't know about script tools, but I thought I could just do this is python script through the expression Advanced mode.  I'm not sure if this is making sense, so I've attached a screen capture of the interface I'm using in creating the dimension style text properties and expression that is failing.  As mentioned, I'm not that good at writing code, but I thought this logic would work.  Please help!  Any suggestions are appreciated.

DimensionTextExpressionError.JPG

Thanks,

Mike

0 Kudos
DarrenWiens2
MVP Alum

Oh, I completely misunderstood how you wanted to use user input. I'm going to say that it's not possible the way you've got it. I'm actually still not quite sure what you're trying to achieve - for each bore drill location, the user needs to type in the number? That could be a lot of typing...

0 Kudos
MikeSullivan
Regular Contributor

It's related to dimension text.  Setting the text to be labeled from an advanced expression on the dimension style.  I didn't think this was possible.  Thanks.

0 Kudos