Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Retrieving properties from catenated SSM property

lee_pellegrin5UBS5
Participant

Retrieving properties from catenated SSM property

lee_pellegrin5UBS5
Participant
Participant

SSM VARIABLE VALUE IS "Test1|test2|test3|test4" - How to return ONLY one of the TEST# data?

0 Me gusta
Responder
344 Vistas
6 Respuestas
Respuestas (6)

wispoxy
Advisor
Advisor

"Test1|test2|test3|test4" < "Test1"|test2|"test3"|test4

or as split...

["Test1","test3"]

 

0 Me gusta

lee_pellegrin5UBS5
Participant
Participant

Split

0 Me gusta

wispoxy
Advisor
Advisor

If you have a string like "Test1|test2|test3|test4" and you want to access a specific “Test#” value, you can do so by splitting the string by the “|” character and then accessing the index of the desired value.

Here’s an example in Python:

 

ssm_variable = "Test1|test2|test3|test4"
values = ssm_variable.split("|")

# To get "Test1"
print(values[0])

# To get "test2"
print(values[1])

# To get "test3"
print(values[2])

# To get "test4"
print(values[3])

 

In this code, split("|") breaks the string into a list where each element is a substring between the “|” characters. The print(values[i]) line then prints the value at index i of the list (remember that list indices in Python start at 0).

 

You can replace the index with the specific index of the “Test#” value you want to access. For example, if you want to get “test2”, you would use values[1] because “test2” is the second value in the list, and list indices start at 0.

 

Please replace the index with the one you need. If you’re using a different programming language, the concept will be similar but the syntax might differ. Let me know if you need help with a different language! :cara_que_sonríe_con_ojos_sonrientes:

0 Me gusta

wispoxy
Advisor
Advisor

The LISP...

(defun split-string (delimiter string)
  (loop for i = 0 then (1+ j)
        as j = (position delimiter string :start i)
        collect (subseq string i j)
        until (null j)))

(let* ((ssm-variable "Test1|test2|test3|test4")
       (values (split-string #\| ssm-variable)))
  (print (nth 0 values)) ; To get "Test1"
  (print (nth 1 values)) ; To get "test2"
  (print (nth 2 values)) ; To get "test3"
  (print (nth 3 values))) ; To get "test4"
0 Me gusta

lee_pellegrin5UBS5
Participant
Participant

Is this possible with DIESEL?

0 Me gusta

wispoxy
Advisor
Advisor

:cara_de_triunfo::cara_de_cansancio: :cara_llorando_a_mares::cara_llorando_a_mares:

Use substr function to extract a specific part. DIESEL does not have built-in functions to split a string by a diameter like "|". Therefore, to extract a specific ‘TEST#’ from your SSM variable, you would need to know the exact position and length of the ‘TEST#’ you want to extract.

 

$(substr, $(getvar, YOUR_VARIABLE_NAME), 7, 5)

 

In this expression, $(getvar, YOUR_VARIABLE_NAME) gets the value of your SSM variable, 7 is the start position of ‘Test2’ in the string (counting from 1), and 5 is the length of ‘Test2’.

Please replace YOUR_VARIABLE_NAME with the actual name of your SSM variable.

Remember that DIESEL has a limit of 10 parameters for all functions!!!!

0 Me gusta