Group nodes via script

User avatar
MilosL
Posts: 46
Joined: Thu Feb 12, 2015 10:53 pm
Location: Cologne, Germany
Contact:

Group nodes via script

#1

Post by MilosL » Thu Aug 27, 2015 8:16 am

Does anyone know how/if nodes can be added to a group via script?

Thanks in advance.

User avatar
svenneve
Fusioneer
Posts: 92
Joined: Fri Sep 12, 2014 1:47 am
Been thanked: 1 time
Contact:

Re: Group nodes via script

#2

Post by svenneve » Fri Aug 28, 2015 5:08 am

It is possible, but it ain't pretty or easy.
For us it was such pain in the rear to get anything done with groups via script we pretty much gave up on using them altogether.

User avatar
pingking
Fusionista
Posts: 733
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 9 times

Re: Group nodes via script

#3

Post by pingking » Fri Aug 28, 2015 12:15 pm

i used this code a long time ago:

Code: Select all

		-- copy all tools to clipboard

		pasting = comp2:Copy(oVisibleToollist)
		comp2:Unlock()

		--close comp
		comp2:Close()
		-- Create a group table called Group1

		gt = { Tools = { Group1 = { __ctor = "GroupOperator" } } }
		gt.Tools.Group1.ViewInfo = { __ctor = "GroupInfo" }
		gt.Tools.Group1.Inputs = {}
		gt.Tools.Group1.Outputs = {}
		gt.Tools.Group1.Outputs.Output1 = { __ctor = "InstanceOutput", SourceOp = tool_out:GetAttrs().TOOLS_Name, Source = "Output" }
		gt.Tools.Group1.Inputs.Input1 = { __ctor = "InstanceInput", SourceOp = tool_in:GetAttrs().TOOLS_Name, Source = "Input" }
		t = fusion:GetClipboard()
		gt.Tools.Group1.Tools = t.Tools

		-- insert tools from clipboard to group

		comp:Paste(gt)
what i did here is that i loaded another comp and inserted this as a group into the actual comp, therefor the comp2 variable
the trick was to have a LUA table for all the tools you need, which you can send to the group:

Code: Select all

group.Tools.GroupName.Tools = LuaTableOfTools
i think i found this in the vfxpedia

User avatar
pingking
Fusionista
Posts: 733
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 9 times

Re: Group nodes via script

#4

Post by pingking » Fri Aug 28, 2015 12:17 pm

here you go:

https://www.steakunderwater.com/VFXPedia ... ul_Scripts

at the very end of this page, there is documented snippet on this

User avatar
MilosL
Posts: 46
Joined: Thu Feb 12, 2015 10:53 pm
Location: Cologne, Germany
Contact:

Re: Group nodes via script

#5

Post by MilosL » Sun Aug 30, 2015 12:52 pm

here you go:

https://www.steakunderwater.com/VFXPedia ... ul_Scripts

at the very end of this page, there is documented snippet on this
Thanks, you just saved the new feature of my xml importer script - import of subsequences.
I hope the new, completely revised version will be ready soon.

User avatar
MilosL
Posts: 46
Joined: Thu Feb 12, 2015 10:53 pm
Location: Cologne, Germany
Contact:

Re: Group nodes via script

#6

Post by MilosL » Wed Sep 02, 2015 5:41 am

If someone is looking for a solution in Python, here is an adapted example script fragment:

Code: Select all

import pprint
comp.AutoPos = False

#create some tools, copy settings and delete from composition
t1 = comp.AddTool("ColorGain")
comp.XPos +=1
t2 = comp.AddTool("AutoGain")
t1s = comp.CopySettings(t1)
t2s = comp.CopySettings(t2)

t1.Delete()
t2.Delete()

# add inputs in t2 tool's table and connect to t1 tool
t2s["Tools"][t2.Name]["Inputs"]=dict()
t2s["Tools"][t2.Name]["Inputs"]["Input"]=dict(__ctor = "Input", SourceOp = t1.Name, Source = "Output")

#add tools to the tools dictionary
all_tools = dict()
all_tools.update(t1s["Tools"])
all_tools.update(t2s["Tools"])

#create group and set up required tables
groupName = "MyGroup"
gt = dict({"Tools":dict({groupName: dict( __ctor = "GroupOperator" ) } )})
gt["Tools"][groupName]["ViewInfo"] = dict(__ctor = "GroupInfo")
gt["Tools"][groupName]["Inputs"]= dict()
gt["Tools"][groupName]["Outputs"]= dict()

#append the list of tools
gt["Tools"][groupName]["Tools"]= all_tools
#Add an external input, referencing the Input of first Tool
gt["Tools"][groupName]["Inputs"]["Input1"] = dict(__ctor = "InstanceInput", SourceOp = t1.Name, Source = "Input")
#Add an external output, referencing the Output of last Tool
gt["Tools"][groupName]["Outputs"]["Output1"] = dict(__ctor = "InstanceOutput", SourceOp = t2.Name, Source = "Output")

#paste completed group into the comp
comp.Paste(gt)

pp = pprint.PrettyPrinter(depth=8)
pp.pprint(gt)