BPy add Path in Textfile from Text-Editor

.hi guys i have a problem by set a path in text line.

I put in a picture, maybe you understand what I mean.

i don't know how to implement the code in such a way that the path is included in the text line (see yellow arrows)

and btw. here is my code from the function:

import bpy

myPath = bpy.path.abspath('GameName\Character\Johnny') #path from "Johnny"

#character list with hardcoded Animations, Speed, Name etc. without correct
#path from character
Text = '''
DIRECTORY: \Animation\Torso\Idle_Stand\\
ANIM_NAME: Idle_Stand
ANIM_SPEED: 1.00
FRAME_FILES: Frame01.obj

DIRECTORY: \Animation\Torso\Spot1\\
ANIM_NAME: Spot_01
ANIM_SPEED: 12.50
FRAME_FILES: Frame01.obj, Frame02.obj, Frame03.obj, Frame04.obj

DIRECTORY: \Animation\Legs\Run\\
ANIM_NAME: Run
ANIM_SPEED: 3.135
FRAME_FILES: Frame01.obj, Frame02.obj, Frame03.obj
'''

t = Text

#checks if this textfile name exists
if "JohnnyAnimDoc" not in bpy.data.texts:
bpy.data.texts.new("JohnnyAnimDoc")
txt = bpy.data.texts['JohnnyAnimDoc']
txt.from_string(t)
txt.current_line_index = 0


I hope there's an answer to my problem.

best regards -DevilSam :)

• Slosh or backslash \  is an "escape character" where the char after defines what it represents newline \n tab \t etc. Need to either escape the slosh, by using two "\\path\\path" or path = r"\path\path" Also most path utils will recognize slash "/"  as the path separator. – batFINGER Jan 6 at 6:25
• Slosh is also used as the python statement continued on next line, if last non whitespace char, hence the double sloshes on EOL's in your text. – batFINGER Jan 6 at 6:34
• ah ok thanks for the info batFINGER. but i still don't know exactly how to do this right :/ – DevilSam Jan 6 at 6:45
• DIRECTORY: \\Animation\\Torso\\Spot1 with the two on the end. They are even a nuisance in markdown lol. – batFINGER Jan 6 at 6:50
• ah ok, but you don't happen to know how i get the "path" from "myPath" into the text line ? – DevilSam Jan 6 at 6:55

Couple of ways.

To include a string in another block string, could use formatting, I like the old and deprecatious % Checkout the python docs for string formatting str.format(...)

text = '''
%s blah
%s blah
%s blah
''' % (("XXX",) * 3) # all 3 occurences
print(text)


output

XXX blah
XXX blah
XXX blah


or use a unique TOKEN and replace

print(text.replace("XXX", "YYY"))


output

YYY blah
YYY blah
YYY blah


Since the parts are paths strongly recommend you lookup in python docs , os.path.join(...).

• thank you very much batFINGER for the nice example :] – DevilSam Jan 6 at 7:24