Select to view content in your preferred language

Escape "inline variable substitution"?

4660
8
02-19-2015 02:59 PM
MarcoBoeringa
MVP Regular Contributor

I am actually running in an interesting minor issue. I have rare case where I have a long string object, in which both a Definition Query is stored using a SQL predicate with a LIKE using the "%" character, and a variable that I would like to go through inline variable substitution.

Now I noticed this inline variable substitution fails, if the string also contains the "%" character. This is probably no surprise, as the LIKE statements' "%" character, can not be replaced, and apparently causes the entire inline variable substitution to fail.

Is there any way "inline variable substitution" can be escaped, so a to prevent an attempt to replace the % character?

E.g., to get an idea, I have something like this:

name LIKE ('%road');%Layer Folder%\LayerName.lyr

0 Kudos
8 Replies
VandanaRaghunathan
New Contributor III

Hello Marco,

Can you attach a screenshot of your model and the tool that you are using for the inline variable substitution?

Thanks,

Vandana

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Hi Vandana,

I have attached a small toolbox with one model in it that demonstrates the issue. Also included in this post two screenshots of the output as I see it. Notice the difference on the output variables when hovered over with the mouse.

I actually consider this as a possible bug, as I see no reason why the inline variable couldn't be replaced. However, it would be nice to have some confirmation.

My environment is ArcGIS 10.2.0 (patches installed) on Windows 7.

*** FAILED variable substitution *** :

Failed_variable_substitution.jpg

*** GOOD variable substitution *** :

Good_variable_substitution.jpg

0 Kudos
VandanaRaghunathan
New Contributor III

Hello Marco,

As you suspected the issue is due the % sign in the variable which is throwing off the inline variable substitution. It has been designed such that when ever there is a percent sign it interprets it as a inline variable substitution. A good analogy would be HTML code. You cannot use the % sign or =  or < >  or any of the other signs in HTML code because it means something else. Therefore inorder to replace that there are codes that indicate these symbols, as demonstrated here: HTML Codes - Table of ascii characters and symbols

To workaround this in Model Builder, you can substitute the % sign in the variable as something else that will not error out and finally return the value with % after the inline substitution is done.

Here is a sample (I used the HTML code for % sign to replace % in this case, however you can use whatever you want):

modelinlinesub1.jpg

modelinlinesub.jpg

modelinlinesub2.jpg

Hope this helps!

Best,

Vandana

MarcoBoeringa
MVP Regular Contributor

Thanks Vandana,

I do appreciate the input. However, I have decided to work around this by using a simple Python string "replace". It is bit tedious, as I needed to include a submodel with iterator, and script, to get it working in my particular situation, but at least it works.

The need to use substitute codes to do this, is not really an option in my design. Well, at least, I don't want to go there yet if it isn't really needed. And as it seems inline variable substitution simply skips the strings in case of such problem, that may be OK for now. I will think about it a bit more keeping your suggestion in mind.

With maintaining % signs, there is of course a very small risk that users will enter something in a LIKE statement, that matches a variable in the model, but since I tend to use rather long descriptive variable names, and knowing the context in which it is going to be used, I think this chance extremely remote.

*** By the way: *** could you test this simple model for me in ArcGIS 10.2.2 if you haven't already done so?

I have tried to upgrade, but noticed issues with my main model using a setup similar to the small demonstration model I included (crash of ArcGIS). I am now slightly wondering if it has to do with this. It was at a point where I didn't want to spent time to figure out the cause, so I stuck with 10.2.0.

0 Kudos
VandanaRaghunathan
New Contributor III

Hello Marco,

Can you elaborate on the crash issue (steps to reproduce it)? I tested this on 10.3 and it works for me (besides the error due to the % sign) without crashing.

I can test on 10.2.2 and let you know what happens.

Thanks,

Vandana

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Well, only trying to open the model (as in Open, not Edit), crashed ArcGIS instantly, even without the normal ESRI crash reporting window opening indicating it had been caught as such. Really boom, gone... I even looked in the Windows logs, but couldn't find a trace of it... (Windows itself kept running).

Do note though, the model I am talking about contains considerably more than this tiny demo model I created here, so the problem may well be somewhere else. I can't share this model with you at this point in time, I am afraid. It runs fine and stable in 10.2.0.

I would appreciate though, if you could try accessing the model by both choosing Open and Edit in 10.2.2, that would at least exclude (or make less likely) this problem as the cause of the instant crash.

0 Kudos
VandanaRaghunathan
New Contributor III

Hello Marco,

Sorry for the delay. I tested this model in 10.2.2 and it did not crash for me. We would need to investigate further to identify the reason for the crash in the bigger model.

Thanks,

Vandana

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Thanks Vandana.

As I wrote, I can't share this bigger model right now. It runs fine in 10.2.0, which is OK for me at this moment in time (although eventually, it will need to work in other versions too...).

0 Kudos