tree copy mode in lua

Forums: tree copy mode in lua
Forum for OctaneRender Lua scripting examples, discussion and support.

tree copy mode in lua

Postby stratified » Fri Feb 28, 2014 12:20 am

stratified Fri Feb 28, 2014 12:20 am
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: tree copy mode in lua

Postby Tugpsx » Fri Feb 28, 2014 5:47 am

Tugpsx Fri Feb 28, 2014 5:47 am
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
Dell Win Vista 32 | NVIDIA Quadro NVS135M | Core2 Duo T7500 2.20GHz | 4GB
CyberPowerPC Win 7 64| NVIDIA GTX660Ti (3G) GTX480(1.5G) | 16GB
Tugpsx
Licensed Customer
Licensed Customer
 
Posts: 1058
Joined: Thu Feb 04, 2010 8:04 pm
Location: Chicago, IL

Re: tree copy mode in lua

Postby bepeg4d » Fri Feb 28, 2014 7:06 am

bepeg4d Fri Feb 28, 2014 7:06 am
it will come surely helpful, thanks thomas ;)
ciao beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 6564
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: tree copy mode in lua

Postby glimpse » Fri Feb 28, 2014 1:52 pm

glimpse Fri Feb 28, 2014 1:52 pm
nice one, thanks Guys!
tomGlimps | [email protected] | 32GB | TitanBlack
Available for Freelance, Coaching & Mentoring
User avatar
glimpse
Licensed Customer
Licensed Customer
 
Posts: 3577
Joined: Wed Jan 26, 2011 2:17 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 1 guest

Sun Aug 25, 2019 11:20 pm [ UTC ]