Just like with pixels or 3d points, you can perform a mirror by subtracting the location of your anchor point from each node's location, multiplying the new x coordinate of each node by -1, then adding the original displacement again to return them to their original location.
To get the location of a tool:
x, y = comp.CurrentFrame.FlowView:GetPos(tool)
To set the location of a tool:
comp.CurrentFrame.FlowView:SetPos(tool, x, y)
To get a list of selected tools:
tools = comp:GetToolList(true)
To perform an operation on each tool in the list:
for i, tool in ipairs(tools) do
<operation>
end
The tricky bit for this script is going to be determining which tool to use as the anchor.
You could do it arbitrarily: Let the script choose whichever tool is at the top of the list as the anchor.
Or you could present a dialogue to ask the user to pick which tool to serve as the anchor.
Or you could let the anchor be determined by a bounding box around the tools—the lower-left corner, for instance. That would require looping through all of the selected tools an additional time in order to get the boundaries.
Here's a script that uses option 1 and mirrors the nodes in the x direction:
- Code: Select all
local tools = comp:GetToolList(true)
local offsetX, offsetY = comp.CurrentFrame.FlowView:GetPos(tools[1])
for i, tool in ipairs(tools) do
local x, y = comp.CurrentFrame.FlowView:GetPos(tool)
x = (x - offsetX) * -1 + offsetX
comp.CurrentFrame.FlowView:SetPos(tool, x, y)
end
This needs to be run as a comp script because tool scripts will run once for each selected node, and that's definitely
not what you want to happen!