1
$\begingroup$

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

I put in a picture, maybe you understand what I mean. path missing by generating

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")
#add "Text" in the textfile
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 :)

$\endgroup$
  • 2
    $\begingroup$ 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. $\endgroup$ – batFINGER Jan 6 at 6:25
  • 2
    $\begingroup$ 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. $\endgroup$ – batFINGER Jan 6 at 6:34
  • $\begingroup$ ah ok thanks for the info batFINGER. but i still don't know exactly how to do this right :/ $\endgroup$ – DevilSam Jan 6 at 6:45
  • $\begingroup$ DIRECTORY: \\Animation\\Torso\\Spot1 with the two on the end. They are even a nuisance in markdown lol. $\endgroup$ – batFINGER Jan 6 at 6:50
  • $\begingroup$ ah ok, but you don't happen to know how i get the "path" from "myPath" into the text line ? $\endgroup$ – DevilSam Jan 6 at 6:55
1
$\begingroup$

Couple of ways.

Already pointed out hassle re slosh in comments

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(...).

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

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.