Welcome to WSL!

Make yourself at home, but before posting, please may I ask you to read the following topics.


Posting 101
Server space, screenshots, and you

Thank you!

PS. please pretty please:


Image

Getting text string from text+ node

JPDoc
Fusionista
Posts: 252
Joined: Tue Sep 02, 2014 8:26 am
Answers: 1
Been thanked: 4 times

Getting text string from text+ node

#1

Post by JPDoc » Sat Nov 26, 2016 11:34 am

I'm taking my first baby steps into scripting in Fusion - and I do mean baby, like "Hello World" level. I've some basic experience with Python (and Perl and Cshell etc) elsewhere and I've done some python stuff with Nuke (which has a lot of pretty good documentation and examples for non-programmers, unlike Fusion I'm afraid) but I'm by no means a programmer.

As a starter project I'm trying to write a python script that gets the text strings from a text+ node and outputs it to a simple text file. A colleague has set this up in Nuke to allow for automatic creation of a text file from a nuke script that is used to make slates for individual shots and it helps the VFX/editorial pipeline - I'm trying to set up the same automatic funcionality for Fusion.

My first major problem is getting the text string from the Text+ node. In the Nuke version the node that makes the text for the script has a specific name - in this case I've used paultext. So I set up a Text+ node in fusion and renamed it "paultext".

I find that I can interogate the node to see what inputs are there by selecting it and then running

from pprint import pprint
pprint(composition.GetToolList(True))
paultext = comp.ActiveTool
x = paultext.GetInputList("Text").values()
for inp in x:
print(inp.GetAttrs()["INPS_Name"])

which gives me a list of "Text" type inputs, one of which is "Styled Text" which is what I assume the actual text info is being called. However when I run

print(paultext.GetInput("Styled Text"))

it returns "None".

If I run it for other inputs like "Style" or "Font" I get the correct output, so I know that I'm interrogating the right node. I've ploughed through the BlackMagic scripting manual but couldn't find any clues as to how to get at the actual text string. I wondered if any of you scripting gurus could point me in the right direction?

I'm probably doing this in all the wrong ways and I haven't even considered how to write out a text file yet but as I said, baby steps . . .

Many thanks in advance.

Tags:

User avatar
miaz3
Fusioneer
Posts: 228
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Contact:

Re: Getting text string from text+ node

#2

Post by miaz3 » Sun Nov 27, 2016 5:47 am

hi,

Code: Select all

textNode = comp.Text1()
print textNode.GetInput("StyledText")

JPDoc
Fusionista
Posts: 252
Joined: Tue Sep 02, 2014 8:26 am
Answers: 1
Been thanked: 4 times

Re: Getting text string from text+ node

#3

Post by JPDoc » Sun Nov 27, 2016 6:30 am

Many thanks Miaz for the quick tip - works great, saved me hours of messing around with syntax.

I don't really get why the list I get from "GetInputList" has a space in "Styled Text" but the actual call doesn't, but I'm sure all will become clear as I get further into it. Now I have to figure out how to parse the result into a few fields and output it into a text file - I'm reasonably clear on how to do this in standard Python so hopefully the Fusion implementation will be ok . . .

Again, mucho thank you.

User avatar
miaz3
Fusioneer
Posts: 228
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Contact:

Re: Getting text string from text+ node

#4

Post by miaz3 » Sun Nov 27, 2016 7:16 am

If you put your mouse in the Styled text field (or any tools) you'll see in bottom left corner ( fusion ui ) the exact name to call.
In this exemple : [Text1.StyledText]

Not to be confused with the RegID of the Tool itself > TextPlus.

Code: Select all

comp.Text1.GetAttrs('TOOLS_RegID')
I don't know if its a good way to add Values but it working:

Code: Select all

textNode({'StyledText' : 'Add new text in textNode's field'})


regards,

JPDoc
Fusionista
Posts: 252
Joined: Tue Sep 02, 2014 8:26 am
Answers: 1
Been thanked: 4 times

Re: Getting text string from text+ node

#5

Post by JPDoc » Sun Nov 27, 2016 11:38 pm

Got it working, thanks again for the tips. A whole new world of scripting fabulousness opens before me . . .

One small question though, just for my own edification. When I run the script the text file is opened but it is 0 bytes - it has no content. This stays this way until I close the comp by closing Fusion, then the text strings are written into the file. I am using a "textfile.close" call at the end of my stuff, and just to be safe I do a "comp.Lock()" at the beginning of the write and a "comp.Unlock()" at the end.

This is not a problem, just that I'm wondering if this normal behaviour or if I've got something wrong (very possible). And if I ever need to script something that is driving an external process it could become an issue, I guess . . .