Retrieve value of ComboControl item in an expression

User avatar
AbdelrahmanMSaid
Fusioneer
Posts: 57
Joined: Tue Oct 04, 2016 9:54 am

Retrieve value of ComboControl item in an expression

#1

Post by AbdelrahmanMSaid » Fri Feb 21, 2020 8:24 am

Hi,

I am building a template for our team that requires them to input a date that will be displayed as text using a Text+ node. Instead of writing the date manually, I would like to add combo controls with the days and the month, so they can just select them. Then, using an expression on the StyledText of the Text+ node, I want to make display the month name. The problem is, I have no idea how can I retrieve the actual string of a combo control item rather than its numerical id.

Is there a way to do that?
by SecondMan » Sat Feb 22, 2020 9:43 am
Yes, you can do this with a ComboIDControl, which is very similar to a ComboControl but uses a different DataType which is sadly not available in the Edit Controls... menu.

With a little manual editing it's pretty easy to do, though. First, let's add a Text+ node, and head to the Edit Controls... menu by right-clicking the node name in the Inspector panel:

Image

Then, create a ComboControl with the names of the months in Items. Note I added the Control to the Text Page, which is the front-most Controls tab in the Text+ node.

Image

Press OK, and the Months Control appears at the bottom of your Text Control Page:

Image

Now for the fun bit. Cut or copy the node out of your Flow View and paste it in your favourite text editor. Then, look for your added UserControl in there, it looks like this:

Image

Now you need to make a couple of simple changes to it; INPID_InputControl = "ComboControl", becomes INPID_InputControl = "ComboIDControl",,

LINKID_DataType = "Number", becomes LINKID_DataType = "FuID",,

wherever you see CCS_AddString, you can (optionallly in this case but it's good practice) add a CCID_AddID, like this:

{ CCS_AddString = "January" }, becomes { CCS_AddString = "January", CCID_AddID = "January", },.

Now it looks like this:

Image

Copy the entire text from the text editor back into a Flow View. Now you have a Text+ node that looks exactly the same, with the same Months control, but internally it works with strings instead of numbers. All you need to do now is add an expression to the Styled Text parameter in the Text+ node and set it to:

Code: Select all

Text(Month.Value)
and you're done:

Image

Here's the full Text+ node for your reference:

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			CtrlWZoom = false,
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				StyledText = Input {
					Value = "May",
					Expression = "Text(Month.Value)",
				},
				Font = Input { Value = "Open Sans", },
				Style = Input { Value = "Bold", },
				VerticalJustificationNew = Input { Value = 3, },
				HorizontalJustificationNew = Input { Value = 3, },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
				Month = Input { Value = FuID { "May" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 1050.67, -52.0303 } },
			UserControls = ordered() {
				Month = {
					{ CCS_AddString = "January", CCID_AddID = "January" },
					{ CCS_AddString = "February", CCID_AddID = "February" },
					{ CCS_AddString = "March", CCID_AddID = "March" },
					{ CCS_AddString = "April", CCID_AddID = "April" },
					{ CCS_AddString = "May", CCID_AddID = "May" },
					{ CCS_AddString = "June", CCID_AddID = "June" },
					{ CCS_AddString = "July", CCID_AddID = "July" },
					{ CCS_AddString = "August", CCID_AddID = "August" },
					{ CCS_AddString = "September", CCID_AddID = "September" },
					{ CCS_AddString = "October", CCID_AddID = "October" },
					{ CCS_AddString = "November", CCID_AddID = "November" },
					{ CCS_AddString = "December", CCID_AddID = "December" },
					INP_MaxAllowed = 1000000,
					INP_Integer = false,
					INPID_InputControl = "ComboIDControl",
					CC_LabelPosition = "Horizontal",
					INP_MaxScale = 1,
					INP_MinScale = 0,
					INP_MinAllowed = -1000000,
					LINKID_DataType = "FuID",
					ICS_ControlPage = "Text",
					LINKS_Name = "Month"
				}
			}
		}
	}
}
Go to full post

User avatar
SirEdric
Fusionator
Posts: 2222
Joined: Tue Aug 05, 2014 10:04 am
Answers: 7
Real name: Eric Westphal
Been thanked: 21 times
Contact:

Re: Retrieve value of ComboControl item in an expression

#2

Post by SirEdric » Fri Feb 21, 2020 11:13 pm

Maybe the TextTimer modifier gets you started?

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			CtrlWZoom = false,
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				Font = Input { Value = "Open Sans", },
				StyledText = Input {
					SourceOp = "TextTimer1",
					Source = "Time",
				},
				Style = Input { Value = "Bold", },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
			},
			ViewInfo = OperatorInfo { Pos = { 55, 16.5 } },
		},
		TextTimer1 = TextTimer {
			CtrlWZoom = false,
			Inputs = {
				Mode = Input { Value = 2, },
				DayOn = Input { Value = 1, },
				DaysOn = Input { Value = 1, },
				MonthOn = Input { Value = 1, },
				YearOn = Input { Value = 1, },
				HoursOn = Input { Value = 0, },
				MinsOn = Input { Value = 0, },
				SecsOn = Input { Value = 0, },
				Twenty4h = Input { Value = 0, },
			},
		}
	},
	ActiveTool = "Text1"
}

User avatar
SecondMan
Site Admin
Posts: 4115
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 14
Location: Vancouver, Canada
Been thanked: 33 times
Contact:

Re: Retrieve value of ComboControl item in an expression

#3

Post by SecondMan » Sat Feb 22, 2020 9:43 am

Yes, you can do this with a ComboIDControl, which is very similar to a ComboControl but uses a different DataType which is sadly not available in the Edit Controls... menu.

With a little manual editing it's pretty easy to do, though. First, let's add a Text+ node, and head to the Edit Controls... menu by right-clicking the node name in the Inspector panel:

Image

Then, create a ComboControl with the names of the months in Items. Note I added the Control to the Text Page, which is the front-most Controls tab in the Text+ node.

Image

Press OK, and the Months Control appears at the bottom of your Text Control Page:

Image

Now for the fun bit. Cut or copy the node out of your Flow View and paste it in your favourite text editor. Then, look for your added UserControl in there, it looks like this:

Image

Now you need to make a couple of simple changes to it; INPID_InputControl = "ComboControl", becomes INPID_InputControl = "ComboIDControl",,

LINKID_DataType = "Number", becomes LINKID_DataType = "FuID",,

wherever you see CCS_AddString, you can (optionallly in this case but it's good practice) add a CCID_AddID, like this:

{ CCS_AddString = "January" }, becomes { CCS_AddString = "January", CCID_AddID = "January", },.

Now it looks like this:

Image

Copy the entire text from the text editor back into a Flow View. Now you have a Text+ node that looks exactly the same, with the same Months control, but internally it works with strings instead of numbers. All you need to do now is add an expression to the Styled Text parameter in the Text+ node and set it to:

Code: Select all

Text(Month.Value)
and you're done:

Image

Here's the full Text+ node for your reference:

Code: Select all

{
	Tools = ordered() {
		Text1 = TextPlus {
			CtrlWZoom = false,
			Inputs = {
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
				StyledText = Input {
					Value = "May",
					Expression = "Text(Month.Value)",
				},
				Font = Input { Value = "Open Sans", },
				Style = Input { Value = "Bold", },
				VerticalJustificationNew = Input { Value = 3, },
				HorizontalJustificationNew = Input { Value = 3, },
				ManualFontKerningPlacement = Input {
					Value = StyledText {
						Array = {
						},
						Value = ""
					},
				},
				Month = Input { Value = FuID { "May" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 1050.67, -52.0303 } },
			UserControls = ordered() {
				Month = {
					{ CCS_AddString = "January", CCID_AddID = "January" },
					{ CCS_AddString = "February", CCID_AddID = "February" },
					{ CCS_AddString = "March", CCID_AddID = "March" },
					{ CCS_AddString = "April", CCID_AddID = "April" },
					{ CCS_AddString = "May", CCID_AddID = "May" },
					{ CCS_AddString = "June", CCID_AddID = "June" },
					{ CCS_AddString = "July", CCID_AddID = "July" },
					{ CCS_AddString = "August", CCID_AddID = "August" },
					{ CCS_AddString = "September", CCID_AddID = "September" },
					{ CCS_AddString = "October", CCID_AddID = "October" },
					{ CCS_AddString = "November", CCID_AddID = "November" },
					{ CCS_AddString = "December", CCID_AddID = "December" },
					INP_MaxAllowed = 1000000,
					INP_Integer = false,
					INPID_InputControl = "ComboIDControl",
					CC_LabelPosition = "Horizontal",
					INP_MaxScale = 1,
					INP_MinScale = 0,
					INP_MinAllowed = -1000000,
					LINKID_DataType = "FuID",
					ICS_ControlPage = "Text",
					LINKS_Name = "Month"
				}
			}
		}
	}
}

User avatar
AbdelrahmanMSaid
Fusioneer
Posts: 57
Joined: Tue Oct 04, 2016 9:54 am

Re: Retrieve value of ComboControl item in an expression

#4

Post by AbdelrahmanMSaid » Sun Feb 23, 2020 3:39 am

Thank you for the help, guys. @SecondMan, the ComboIDControl is brilliant. How on earth is it not available in the Edit Controls menu?

Also, how can I find out about these things? I am still learning Lua, because I have never used it before Fusion, but I don't know how can I find some of these undocumented features of Fusion's API.

User avatar
SecondMan
Site Admin
Posts: 4115
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 14
Location: Vancouver, Canada
Been thanked: 33 times
Contact:

Re: Retrieve value of ComboControl item in an expression

#5

Post by SecondMan » Sun Feb 23, 2020 9:31 am

AbdelrahmanMSaid wrote:
Sun Feb 23, 2020 3:39 am
how can I find out about these things?
By coming to We Suck Less :)

WSL's Advanced Search page allows you to search the forum as well as VFXPedia, which is a great start. And if that fails, just ask, like you've done here...

User avatar
Millolab
Fusionista
Posts: 285
Joined: Wed Oct 24, 2018 6:26 am
Been thanked: 21 times
Contact:

Re: Retrieve value of ComboControl item in an expression

#6

Post by Millolab » Sun Feb 23, 2020 12:20 pm

@SecondMan that's great to know! Thanks!