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

Change text+ size so that it fits the background width

User avatar
noelevatorstudio
Posts: 23
Joined: Thu Nov 21, 2019 8:37 am
Been thanked: 2 times

Change text+ size so that it fits the background width

#1

Post by noelevatorstudio » Mon Sep 14, 2020 8:43 am

This is pretty much a shot in the dark since my attempts didn't get me anywhere.

I would like to automate the size of a text+ to fit the background width since i need to make a loong series of file that are pretty much identical.

I know i can get the width of a text+ output by subtracting Text1.Output.DataWindow[1] and Text1.Output.DataWindow[3], but i have no idea how to coordinate this data with the text size, since it depends from the number of characters and the width of every character.

Does anyone have any idea on how to approach this?

Thanks!
by Midgardsormr » Mon Sep 14, 2020 1:21 pm
TheBloke wrote:
Mon Sep 14, 2020 9:43 am
While this is being discussed, could anyone tell me why I can never seem to use eg Text2.Output.DataWindow[1]? I've seen it mentioned before, but whenever I try it, eg here in the Console:

<snip>

Same from a Simple Expression - trying to reference DataWindow in an expression causes the node to error.

If someone can show me how to get that working, I might have a method for the OP.
I seem to remember getting it to work in the Console at some point, but a quick try right now got the same result as you did. But here it is in a Simple Expression:

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input { Value = "FUSION", },
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 459, 60 } },
		},
		Merge1 = Merge {
			Inputs = {
				Background = Input {
					SourceOp = "Background1",
					Source = "Output",
				},
				Foreground = Input {
					SourceOp = "Text1",
					Source = "Output",
				},
				PerformDepthMerge = Input { Value = 0, },
			},
			ViewInfo = OperatorInfo { Pos = { 565, 107 } },
		},
		Background1 = Background {
			CtrlWZoom = false,
			Inputs = {
				Width = Input {
					Value = 380,
					Expression = "Text1.Output.DataWindow[3]-Text1.Output.DataWindow[1]+50",
				},
				Height = Input {
					Value = 119,
					Expression = "Text1.Output.DataWindow[4]-Text1.Output.DataWindow[2]+50",
				},
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 455, 108 } },
		}
	}
}
Now, as for the original question, it's an interesting puzzle! What you need to do is find a ratio between the background's width and the Text's width, then use that to drive the Transform's Size control.

In this example, I've used the Edit Controls feature to make the Frame Reference Size parameters animatable, which allows me to put an expression on them. I use the DataWindow expression demonstrated above to set the Reference Size. Then I set another expression on the width getting the ratio I want: Background2.Width / Width

If the width of Text1's DataWindow is the same as the Width input of Background2, then the expression evaluates to 1, and the Text is not transformed. If the size of the Background changes, then the Transform proportionally modifies the Text+. I've added a 50 pixel margin in the expressions that reference the DataWindow so the text doesn't crowd the edges of the background(s).

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input { Value = "FUSION", },
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 605, 82.5 } },
		},
		Background2 = Background {
			Inputs = {
				Width = Input { Value = 1557, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 605, 115.5 } },
		},
		Transform1 = Transform {
			CtrlWZoom = false,
			Inputs = {
				Size = Input { Expression = "Background2.Width/Width", },
				ReferenceSize = Input { Value = 1, },
				Input = Input {
					SourceOp = "Text1",
					Source = "Output",
				},
				Width = Input { Expression = "Text1.Output.DataWindow[3]-Text1.Output.DataWindow[1]+50", },
				Height = Input { Expression = "Text1.Output.DataWindow[4]-Text1.Output.DataWindow[2]+50", },
			},
			ViewInfo = OperatorInfo { Pos = { 770, 82.5 } },
			UserControls = ordered() {
				Width = {
					LINKS_Name = "Width",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				},
				Height = {
					LINKS_Name = "Height",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				}
			}
		},
		Merge2 = Merge {
			Inputs = {
				Background = Input {
					SourceOp = "Background2",
					Source = "Output",
				},
				Foreground = Input {
					SourceOp = "Transform1",
					Source = "Output",
				},
				PerformDepthMerge = Input { Value = 0, },
			},
			ViewInfo = OperatorInfo { Pos = { 880, 115.5 } },
		}
	}
}
Go to full post

User avatar
Midgardsormr
Fusionator
Posts: 1907
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 18
Location: Los Angeles, CA, USA
Been thanked: 143 times
Contact:

Re: Change text+ size so that it fits the background width

#2

Post by Midgardsormr » Mon Sep 14, 2020 9:13 am

I'm a little confused. Where is the width you want to match coming from? It sounds like you want to get the size of the raster of a Text+, then use that to drive the Text size of that same Text+, but that would change the output size, so you'd have to update the Text size, which would change the output size... you see where I'm going with that.

So I'm guessing that the bit about reading the DataWindow of the Text+ is a red herring.

User avatar
TheBloke
Fusioneer
Posts: 139
Joined: Wed Jun 17, 2020 6:02 am
Answers: 1
Been thanked: 22 times

Re: Change text+ size so that it fits the background width

#3

Post by TheBloke » Mon Sep 14, 2020 9:43 am

While this is being discussed, could anyone tell me why I can never seem to use eg Text2.Output.DataWindow[1]? I've seen it mentioned before, but whenever I try it, eg here in the Console:

Code: Select all

Lua> ==Text2
Text+ (0x0x7fd902beb210) [App: 'Fusion' on 127.0.0.1, UUID: 32795583-a524-4b1e-a318-fce1bbbf1ec5]
Lua> ==Text2.Output
Output (0x0x7fd9024f6290) [App: 'Fusion' on 127.0.0.1, UUID: 32795583-a524-4b1e-a318-fce1bbbf1ec5]
Lua> ==Text2.Output.DataWindow
nil
Lua> ==Text2.Output.DataWindow[1]
[string "???"]:1: attempt to index field 'DataWindow' (a nil value)
Lua> txt2 = comp:FindTool("Text2")
Lua> ==txt2
Text+ (0x0x7fd902beb210) [App: 'Fusion' on 127.0.0.1, UUID: 32795583-a524-4b1e-a318-fce1bbbf1ec5]
Lua> ==txt2.Output.DataWindow
nil
Same from a Simple Expression - trying to reference DataWindow in an expression causes the node to error.

If someone can show me how to get that working, I might have a method for the OP.

User avatar
noelevatorstudio
Posts: 23
Joined: Thu Nov 21, 2019 8:37 am
Been thanked: 2 times

Re: Change text+ size so that it fits the background width

#4

Post by noelevatorstudio » Mon Sep 14, 2020 10:11 am

Midgardsormr wrote:
Mon Sep 14, 2020 9:13 am
I'm a little confused. Where is the width you want to match coming from? It sounds like you want to get the size of the raster of a Text+, then use that to drive the Text size of that same Text+, but that would change the output size, so you'd have to update the Text size, which would change the output size... you see where I'm going with that.

So I'm guessing that the bit about reading the DataWindow of the Text+ is a red herring.
Yeah, i'm confused too, sorry :?

I would use a transform after the text+ node to make it fit proportionally to the background.
It doesn't need to be the text+ itself, i just want to fit it automatically by scaling the text.

User avatar
Midgardsormr
Fusionator
Posts: 1907
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 18
Location: Los Angeles, CA, USA
Been thanked: 143 times
Contact:

Re: Change text+ size so that it fits the background width

#5

Post by Midgardsormr » Mon Sep 14, 2020 1:21 pm

TheBloke wrote:
Mon Sep 14, 2020 9:43 am
While this is being discussed, could anyone tell me why I can never seem to use eg Text2.Output.DataWindow[1]? I've seen it mentioned before, but whenever I try it, eg here in the Console:

<snip>

Same from a Simple Expression - trying to reference DataWindow in an expression causes the node to error.

If someone can show me how to get that working, I might have a method for the OP.
I seem to remember getting it to work in the Console at some point, but a quick try right now got the same result as you did. But here it is in a Simple Expression:

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input { Value = "FUSION", },
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 459, 60 } },
		},
		Merge1 = Merge {
			Inputs = {
				Background = Input {
					SourceOp = "Background1",
					Source = "Output",
				},
				Foreground = Input {
					SourceOp = "Text1",
					Source = "Output",
				},
				PerformDepthMerge = Input { Value = 0, },
			},
			ViewInfo = OperatorInfo { Pos = { 565, 107 } },
		},
		Background1 = Background {
			CtrlWZoom = false,
			Inputs = {
				Width = Input {
					Value = 380,
					Expression = "Text1.Output.DataWindow[3]-Text1.Output.DataWindow[1]+50",
				},
				Height = Input {
					Value = 119,
					Expression = "Text1.Output.DataWindow[4]-Text1.Output.DataWindow[2]+50",
				},
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 455, 108 } },
		}
	}
}
Now, as for the original question, it's an interesting puzzle! What you need to do is find a ratio between the background's width and the Text's width, then use that to drive the Transform's Size control.

In this example, I've used the Edit Controls feature to make the Frame Reference Size parameters animatable, which allows me to put an expression on them. I use the DataWindow expression demonstrated above to set the Reference Size. Then I set another expression on the width getting the ratio I want: Background2.Width / Width

If the width of Text1's DataWindow is the same as the Width input of Background2, then the expression evaluates to 1, and the Text is not transformed. If the size of the Background changes, then the Transform proportionally modifies the Text+. I've added a 50 pixel margin in the expressions that reference the DataWindow so the text doesn't crowd the edges of the background(s).

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input { Value = "FUSION", },
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 605, 82.5 } },
		},
		Background2 = Background {
			Inputs = {
				Width = Input { Value = 1557, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 605, 115.5 } },
		},
		Transform1 = Transform {
			CtrlWZoom = false,
			Inputs = {
				Size = Input { Expression = "Background2.Width/Width", },
				ReferenceSize = Input { Value = 1, },
				Input = Input {
					SourceOp = "Text1",
					Source = "Output",
				},
				Width = Input { Expression = "Text1.Output.DataWindow[3]-Text1.Output.DataWindow[1]+50", },
				Height = Input { Expression = "Text1.Output.DataWindow[4]-Text1.Output.DataWindow[2]+50", },
			},
			ViewInfo = OperatorInfo { Pos = { 770, 82.5 } },
			UserControls = ordered() {
				Width = {
					LINKS_Name = "Width",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				},
				Height = {
					LINKS_Name = "Height",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				}
			}
		},
		Merge2 = Merge {
			Inputs = {
				Background = Input {
					SourceOp = "Background2",
					Source = "Output",
				},
				Foreground = Input {
					SourceOp = "Transform1",
					Source = "Output",
				},
				PerformDepthMerge = Input { Value = 0, },
			},
			ViewInfo = OperatorInfo { Pos = { 880, 115.5 } },
		}
	}
}

User avatar
TheBloke
Fusioneer
Posts: 139
Joined: Wed Jun 17, 2020 6:02 am
Answers: 1
Been thanked: 22 times

Re: Change text+ size so that it fits the background width

#6

Post by TheBloke » Mon Sep 14, 2020 2:32 pm

Midgardsormr wrote:
Mon Sep 14, 2020 1:21 pm
I seem to remember getting it to work in the Console at some point, but a quick try right now got the same result as you did. But here it is in a Simple Expression:
Ahh, thank you. I see the problem now re Simple Expression:

This works fine in eg a Background node, like in your code: Text2.Output.DataWindow[3]-Text2.Output.DataWindow[1]+50

But the exact same code fails when placed on node Text2. It seems that a node can't query its own DataWindow?
Midgardsormr wrote:
Mon Sep 14, 2020 1:21 pm
If the width of Text1's DataWindow is the same as the Width input of Background2, then the expression evaluates to 1, and the Text is not transformed. If the size of the Background changes, then the Transform proportionally modifies the Text+. I've added a 50 pixel margin in the expressions that reference the DataWindow so the text doesn't crowd the edges of the background(s).
Ahh very elegant! Well done.

The method I was going to use was to much too over-complex. I was trying to modify the Text2.Size directly in a while loop: If the Text2 size (as calculated from DataWindow) is wider than screen width (eg from a Background node Width), make the Text size smaller. Repeat until Text is small enough.

Everything I tried ran up against issues. I can't seem to adjust the Text size from either an Expression, or a Frame Render script. In both cases I tried this on another node, because as mentioned I can't query the DataWindow on the Text node itself. Any attempts to set Text2.Size = X from another node just seem to do nothing.

So I was stuck between two problems: it's only possible to set the Text+ size on the Text+ node itself, but it's not possible to read the DataWindow from the Text+ node.

I even tried some indirection, eg putting the DataWindow values in a control on another node via an Expression, then reading that from the Text+ node. That led to Fusion hanging.

In fact, Fusion Studio 16 hangs even with the following simple arrangement:
Merge4 SetTextSize (UserControl) with expression: Text2.Output.DataWindow[3] - Text2.Output.DataWindow[1] + 50
Text2 SetTextSize (UserControl) with expression: Merge4.SetTextSize

Not that it's necessary because your method works great. But it seems every time I try something a bit more complex like this, I end up with errors or freezes or usually both :)

User avatar
Midgardsormr
Fusionator
Posts: 1907
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 18
Location: Los Angeles, CA, USA
Been thanked: 143 times
Contact:

Re: Change text+ size so that it fits the background width

#7

Post by Midgardsormr » Mon Sep 14, 2020 2:50 pm

TheBloke wrote:
Mon Sep 14, 2020 2:32 pm
It seems that a node can't query its own DataWindow?
See my initial response. The DataWindow is an output of the node, so you can't reference it in anything upstream because it will create a feedback loop. You managed to side-step Fusion's error condition checking (which will reject actions like trying to plug a downstream output into a tool's Effect Mask), and the hang was due to the infinite loop you made.

That said, there does seem to be something weird about the Text+ Size control. I can connect it to the slider on a Custom Tool, but the tool fails if I try to connect it directly to the Size of a Transform. However, if I link the Transform to the CT, then the CT to the Text Size, then it works.

User avatar
noelevatorstudio
Posts: 23
Joined: Thu Nov 21, 2019 8:37 am
Been thanked: 2 times

Re: Change text+ size so that it fits the background width

#8

Post by noelevatorstudio » Tue Sep 15, 2020 8:09 am

Midgardsormr wrote:
Mon Sep 14, 2020 1:21 pm
Now, as for the original question, it's an interesting puzzle! What you need to do is find a ratio between the background's width and the Text's width, then use that to drive the Transform's Size control.

In this example, I've used the Edit Controls feature to make the Frame Reference Size parameters animatable, which allows me to put an expression on them. I use the DataWindow expression demonstrated above to set the Reference Size. Then I set another expression on the width getting the ratio I want: Background2.Width / Width

If the width of Text1's DataWindow is the same as the Width input of Background2, then the expression evaluates to 1, and the Text is not transformed. If the size of the Background changes, then the Transform proportionally modifies the Text+. I've added a 50 pixel margin in the expressions that reference the DataWindow so the text doesn't crowd the edges of the background(s).

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input { Value = "FUSION", },
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 605, 82.5 } },
		},
		Background2 = Background {
			Inputs = {
				Width = Input { Value = 1557, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 605, 115.5 } },
		},
		Transform1 = Transform {
			CtrlWZoom = false,
			Inputs = {
				Size = Input { Expression = "Background2.Width/Width", },
				ReferenceSize = Input { Value = 1, },
				Input = Input {
					SourceOp = "Text1",
					Source = "Output",
				},
				Width = Input { Expression = "Text1.Output.DataWindow[3]-Text1.Output.DataWindow[1]+50", },
				Height = Input { Expression = "Text1.Output.DataWindow[4]-Text1.Output.DataWindow[2]+50", },
			},
			ViewInfo = OperatorInfo { Pos = { 770, 82.5 } },
			UserControls = ordered() {
				Width = {
					LINKS_Name = "Width",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				},
				Height = {
					LINKS_Name = "Height",
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					INP_Default = 1,
					INP_Integer = true,
					INP_MinScale = 1,
					INP_MaxScale = 2048,
					INP_MinAllowed = 1,
					INP_MaxAllowed = 32767,
					IC_Steps = 2047,
					INP_Passive = true,
				}
			}
		},
		Merge2 = Merge {
			Inputs = {
				Background = Input {
					SourceOp = "Background2",
					Source = "Output",
				},
				Foreground = Input {
					SourceOp = "Transform1",
					Source = "Output",
				},
				PerformDepthMerge = Input { Value = 0, },
			},
			ViewInfo = OperatorInfo { Pos = { 880, 115.5 } },
		}
	}
}
Wow Bryan you made my day, it works better than what i hoped for!
Thank you so much