Goal: I need to upgrade an existing ModelBuilder where the expressions use Python 9.3.

Work process & Goal: My *.mxd Have 1 attribute field containing the following build: X1-X2-X3-x4_x5_x6-x7.
Example: G-OI-KI-VUUR_NAAMGEVING_0000101111_VECT_12X001111-X. I tryed to split is on the ‘-’ and ‘_’ signs because the names have a different length.

My goal is putting the fields X1 - X7 in separate text-fields by using a ModelBuilder which is coded with Python 9.3.

Issue: one of those 'transformations' (X4) isn’t working properly. I used | !LAYER!.split("-")[3] | A new field is created, but I got as a result: x4_x5_x6-x7. I only wanted x4.

Matthieu Brbt came with a solution to use:


instead. Unfortunately this ended up with an error: 000539: Indentation Error: unexpected indent (, line 1) Failed to execute (Calculate Field) Matthieu suggested to check for empty spaces in the expression but those were not here.

This is what my expression looks like:

enter image description here

How can I make a split based on the ‘-’ and ‘_’ for field x4 ?

  • 1
    here you divide Type by name (two strings). I don't understand what you want to do with this ratio. Could you give an example of input and output ? – radouxju Jan 29 '14 at 9:10
  • Radouxju, thank you for your reaction. The information is shown in my question is 1 field(string) containing the following build: X1-X2-X3-x4_x5_x6_x7. What I tried to do is place X4 in a seperate field (text) by using a modelbuilder. In this modelbuilder I (try to) say: create a new field then, make a split, so only X4 is placed in a new field. In the current state the expression only make a split between x3 and x4 but not between x4 and x5. So the new field contains X4_X5_X6_X7. Some how I can not make a second split on "_" (between X4 and X5). – MbZ Jan 29 '14 at 9:31
  • i did use the python expression: !LAYER!.split("-")[3] / !LAYER!.split("_")[1]. Can u show me that is wrong? – MbZ Jan 29 '14 at 9:33
  • 1
    @matthieu Brbt's answer seems correct : splitting the result of your first split. (first split ).split() – radouxju Jan 29 '14 at 9:39
  • Are you trying to do this in a Calculate Field tool or somewhere else? – PolyGeo Jan 29 '14 at 12:12

If you want to show the type-field you can try with this :

  • Matthieu, thank you: i tried your code ( (!LAYER!.split("-")[-1]).split("")[0]) but I got the following ERROR 000539: IndentationError: unexpected indent (<expression>, line 1) Failed to execute (Calculate Field). I also tried the combination. My build: X1-X2-X3-x4_x5_x6_x7 so I also tried (!LAYER!.split("-")[3]).split("")[1] but no succes :S – MbZ Jan 29 '14 at 9:41
  • 1
    Checks if'there space after or before the python expression. And i think that the correct code is (!LAYER!.split("-"))[-1]).split("_")[0] – Matthieu Brbt Jan 29 '14 at 10:17
  • i tried it with and widhout spaces. unfortiantly widhout succes. Now I am wondering how i can give you more information to solve this problem. Shall i post an example or is not the purpose of this site? – MbZ Jan 29 '14 at 10:45
  • @MbZ To provide additional details just click on the edit button beneath your Question to revise it. – PolyGeo Jan 29 '14 at 11:17
  • Updated my question – MbZ Jan 29 '14 at 12:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.