Jump to: Board index » General » Fusion

Fixed: Setting StyledText at keyframes from a program.

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

AndyThirtover

  • Posts: 73
  • Joined: Sun Oct 04, 2015 12:01 pm

Fixed: Setting StyledText at keyframes from a program.

PostMon Jan 11, 2016 10:15 am

Dear Forum.

I'm trying to program setting the StyledText values of a text+ tool at particular KeyFrames.

I created a super simple comp with four KeyFrames and then set about using Python to interrogate the values.

In the Comp I can see that I would expect a structure to look like this:

KeyFrames = {
[0] = { 0, RH = { 13.3333333333333, 0.333333333333333 }, Flags = { Linear = true, LockedY = true }, Value = Text {
Value = "ABC"
} },
[40] = { 1, LH = { 26.6666666666667, 0.666666666666667 }, RH = { 53.3333333333333, 1.33333333333333 }, Flags = { Linear = true, LockedY = true }, Value = Text {
Value = "ABC1"
} },
[80] = { 2, LH = { 66.6666666666667, 1.66666666666667 }, RH = { 86.6666666666667, 2.33333333333333 }, Flags = { Linear = true, LockedY = true }, Value = Text {
Value = "ABC2"
} },
[100] = { 3, LH = { 93.3333333333333, 2.66666666666667 }, Flags = { Linear = true, LockedY = true }, Value = Text {
Value = "ABC3"
} }
}

However I only get this from Python:

KeyFrames of StyledText: {1.0: 0.0, 2.0: 40.0, 3.0: 80.0, 4.0: 100.0}

And this, from exporting the Spline:

DFSP
0.000000 0.000000
40.000000 1.000000
80.000000 2.000000
100.000000 3.000000

Here's my code:


kf = comp.TextTarget.StyledText.GetKeyFrames()

print "KeyFrames of StyledText: {0}".format(kf)
print "SplineColor of StyledText: {0}".format(comp.TextTarget.StyledText.SplineColor)
print "======= Attributes and Values of Styled Text ========"
for key in comp.TextTarget.StyledText.GetAttrs().keys():
print "Key: {0} Value {1}".format(key, comp.TextTarget.StyledText.GetAttrs()[key])


And, here are the results of running that code:

KeyFrames of StyledText: {1.0: 0.0, 2.0: 40.0, 3.0: 80.0, 4.0: 100.0}
SplineColor of StyledText: None
======= Attributes and Values of Styled Text ========
Key: INPB_IC_StepRestrict Value False
Key: INPN_MinAllowed Value -1000000.0
Key: INPI_Priority Value 0.0
Key: INPS_ICS_ControlPage Value Text
Key: INPN_MaxScale Value 1.0
Key: INPB_ForceNotify Value False
Key: INPB_PC_Visible Value False
Key: INPI_IC_ControlGroup Value 0.0
Key: INPI_IC_ControlID Value 0.0
Key: INPI_PC_ControlID Value 0.0
Key: INPS_ID Value StyledText
Key: INPI_IC_DisplayedPrecision Value 0.0
Key: INPN_IC_Center Value 0.0
Key: INPB_Disabled Value False
Key: INPB_Required Value True
Key: INPN_Default Value 0.0
Key: INPB_IC_TimeType Value False
Key: INPB_InteractivePassive Value False
Key: INPB_SendRequest Value True
Key: INPS_DataType Value Text
Key: INPN_UserData2 Value 0.0
Key: INPN_DefaultX Value 0.0
Key: INPI_SubType Value 0.0
Key: INPB_TextEditControl_Wrap Value False
Key: INPI_NumSlots Value 1.0
Key: INPB_InitialNotify Value False
Key: INPI_SetupPriority Value 0.0
Key: INPN_MaxAllowed Value 1000000.0
Key: INPB_Passive Value False
Key: INPB_TextEditControl_ReadOnly Value False
Key: INPID_InputControl Value TextEditControl
Key: INPI_IC_ControlPage Value 1.0
Key: INPB_Connected Value True
Key: INPB_Integer Value False
Key: INPS_Name Value Styled Text
Key: INPB_IC_Visible Value False
Key: INPI_PC_ControlGroup Value 0.0
Key: INPN_MinScale Value 0.0
Key: INPI_IC_Steps Value 0.0
Key: INPB_PC_FastSampleRate Value False
Key: INPN_ICD_Width Value 0.0
Key: INPB_DoNotifyChanged Value False
Key: INPB_Active Value True
Key: INPB_OpMenu Value False
Key: INPI_TextEditControl_Lines Value 10.0
Key: INPID_PreviewControl Value PreviewControlStyledText
Key: INPI_PC_GrabPriority Value 0.0
Key: INPN_UserData3 Value 0.0
Key: INPN_DefaultY Value 0.0
Key: INPB_External Value True
Key: INPI_UserData Value 0.0

=================================

I can't see any way of accessing the other attributes of the KeyFrames.

Now I realise that I could write some Python to directly inject these into the Comp, however this doesn't feel right?

Am I missing something? is there a neat way of doing this? Am I treating the Class wrong.

Many thanks for any guidance ...... Andy
Last edited by AndyThirtover on Tue Jan 12, 2016 2:55 pm, edited 1 time in total.
Offline
User avatar

michael vorberg

  • Posts: 943
  • Joined: Wed Nov 12, 2014 8:47 pm
  • Location: stuttgart, germany

Re: Stumped: Setting StyledText at keyframes from a program

PostMon Jan 11, 2016 11:08 pm

Code: Select all
myTool = comp.Text1()

if myTool.AddModifier("StyledText","BezierSpline"):
    myTool.StyledText[0] = "ABC"
    myTool.StyledText[10] = "CBA"



hope that helps to get things started
Offline

AndyThirtover

  • Posts: 73
  • Joined: Sun Oct 04, 2015 12:01 pm

Re: Stumped: Setting StyledText at keyframes from a program

PostTue Jan 12, 2016 8:48 am

Michael

Extra Double Thanks. I used your solution to google and came up with this:

http://documents.blackmagicdesign.com/F ... erence.pdf

Which looks helpful.

My normal trick for working out what methods an object has failed:

target = comp.TextTarget
print "Methods of target: {0}".format(dir(target))

This simply returns []

Using your guide I'll be able to create a generic tool for loading text from files into specific tools.

Once again thanks --- Andy
Offline

AndyThirtover

  • Posts: 73
  • Joined: Sun Oct 04, 2015 12:01 pm

Example Program with Dialog to change Text+ on KFrames

PostTue Jan 12, 2016 8:38 pm

Here's the program that I wrote to do this:
Code: Select all
# Find Text+ Tools.  Change the Text on Keyframes of the chosen one
import textwrap

def findtool(name):
   tools = comp.GetToolList()
   print "ToolList: {0}".format(repr(tools))
   for t in tools:
      print "ID found: {0} with Name ".format(tools[t].ID, tools[t].Name)
      if tools[t].Name == name:
         return tools[t]
   return None

def find_by_type(name_of_type):
   tools = comp.GetToolList()
   ret_list = []
   for t in tools:
      if tools[t].ID == name_of_type:
         ret_list.append(tools[t])
   return ret_list

def format_text(text,wrap):
   lines = textwrap.wrap(text,wrap)
   output = ""
   for line in lines:
      output += line.replace("\\n", '\n') + '\n'
   return output

options = {}
options_index = 0
for text_tool in find_by_type('TextPlus'):
   print "Tool ID: {0} Tool Name: {1}".format(text_tool.ID, text_tool.Name)
   options[options_index] = text_tool.Name
   options_index += 1

dialog = {
        1:{1: "TextToolName", "Name":"Which Text Tool",  2: "Dropdown", "Options" : options},
        2:{1: "WrapValue", "Name": "Characters to Wrap", 2: "Slider", "Default": 70, "Min": 20, "Max": 200},
        3:{1: "FileName", "Name":"Path to Text Info File", 2: "FileBrowse", "Default":comp.GetAttrs()['COMPS_FileName']}
}

answer = comp.AskUser("Change Text at Keyframes:", dialog)
print "AskUser Result: {0}".format(answer)


text_file = open(answer['FileName'], "r")
text_data = text_file.read()

lines = text_data.split('\n')

target = findtool(options[int(answer['TextToolName'])])

if target.AddModifier("StyledText","BezierSpline"):
   for line in lines:
      parts = line.split('"',2)
      framenumber = int(parts[0])
      new_text = format_text(parts[1],int(answer['WrapValue']))
      print "Will Set Frame: {0} to {1}".format(framenumber,new_text)
      target.StyledText[framenumber] = new_text



============
And here's an example input file:
Code: Select all
10 "Here is the text from a file"
40 "This has changed, \n but it is still from a file"
100 "More stuff from the file of fileness"
140 "This is a lot of text, it may even go over one line,\n I expect it to be a very long line. \n We should still remember that this text came from a file, this file in fact, not that you'd know unless I put the actual file name in it, for example keyframes.txt which is what I shall be naming this file when I get around to it"


Return to Fusion

Who is online

Users browsing this forum: No registered users and 44 guests