Page 1 of 1

tree copy mode in lua

PostPosted: Fri Feb 28, 2014 12:20 am
by stratified
Hi Everybody,

Here's a little script to copy and paste a full node tree. The root of the tree is the selected node. To use it, just select a node and run the script. The script is mapped to alt + c but you can change this of course. Might be useless 99.99% of the time but I think it's nifty :D

This only works with release 1.34 and higher.

Here's a visually what the script does:

tree-copy-before.png
select the root node of the tree to copy and hit alt+c


tree-copy-after.png
here's the result (I already moved the copied tree to the right)


Code: Select all
-- Creates a copy of tree starting at the selected item. The copy is immediately
-- pasted into the current project and the copied tree is selected.
--
-- @description creates an item tree copy
-- @author      Thomas Loockx
-- @version     0.1
-- @shortcut    alt+c

-- get the current selection
local selection = octane.project.getSelection()

-- only do something if we have a single selection
if #selection == 1 then
    -- create a root graph to copy into
    local copyGraph = octane.nodegraph.createRootGraph("Copy Tree Graph")
    -- copy the full tree into the copy graph
    local copyRoot = copyGraph:copyItemTree(selection[1])
    -- unclutter it a bit
    copyGraph:unfold()
    -- copy it into the scene graph
    local copies = octane.nodegraph.getRootGraph():copyFrom(copyGraph:getOwnedItems())
    -- select all those copied items
    octane.project.clearSelection()
    for i, item in pairs(copies) do
        octane.project.select(item)
    end
end


cheers,
Thomas

Re: tree copy mode in lua

PostPosted: Fri Feb 28, 2014 5:47 am
by Tugpsx
Thanks, sometime the simplest scripts makes the most desired. This shows the process that can be used to replicate a node tree and possible link them

Re: tree copy mode in lua

PostPosted: Fri Feb 28, 2014 7:06 am
by bepeg4d
it will come surely helpful, thanks thomas ;)
ciao beppe

Re: tree copy mode in lua

PostPosted: Fri Feb 28, 2014 1:52 pm
by glimpse
nice one, thanks Guys!