3
$\begingroup$

I am trying to access just the last few nodes of a data path, however blender tries to execute it when I try to use split or similar functions. What is the proper way to do this?

The data: bpy.data.scenes['Scene'].sequence_editor.sequences_all["Image0001.png"]

What I want: sequences_all["Image0001.png"]

Some things I've tried so far:

The split function:

n = bpy.context.selected_sequences
x = n[0]
x = str(x)
print(x.split(str='.'))

The problem is blender tries to interpret split as an attribute of the image sequence.

I need a dynamic result, as values could change in the first few parts. A way to just capture the "data path" of the selected VSE strip could potentially work as well.

$\endgroup$
2
$\begingroup$

The script below gets the data path, converts it to a string. Then does the manipulation on it to get the desired part.

I split the string on "sequence_editor." because everything after that (except for the closing bracket) is what you want, a period would also work.

After splitting the string (string[-1]) that line gets the last item in the list.
Using your data path the list would look like this:

["[bpy.data.scenes['Scene'].", 'sequences_all["Image0001.png"]]']

The last item in the list sequences_all["Image0001.png"]] only needs to have the trailing bracket removed (last line of the script.)

import bpy

path = bpy.context.selected_sequences
string = str(path) #convert data path to string
string = string.split("sequence_editor.") #split string in to a list
string = string[-1] # get last piece
string = string[:-1] # remove last character
print(string)

Your problem was you were trying to get the first part of the path x = n[0] before turning it in to a string and then splitting it into a list.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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