Page 1 of 2
					
				Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 1:38 pm
				by manalokos
				Hello
I have absolutelly no experience in scripting, but would like to request a probably easy task that would be helpful to most in our community.
A small script that would automatically refresh all the scatter nodes in a scene. Would this be difficult to achieve through scripting?
Thanks
Best regards
Filipe
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 7:39 pm
				by stratified
				hi there,
Sure that's possible. Here's a small code snippet for the users who want to try and tackle this problem (getSelection is new in 1.23). It shouldn't be too hard:
Code: Select all
-- gets the selected scatter node
scatter = octane.project.getSelection()[1]
-- 3x4 matrices (actually, they are standard 4x4 transform matrices in disguise but we ommit the last (0, 0, 0, 1) row)
transforms = 
{
    -- unit matrix
    { 
        { 1, 0, 0, 0 },
        { 0, 1, 0, 0 },
        { 0, 0, 1, 0 }
    },
    -- transformed matrix ( 2x scaling + translation)
    {
        { 2, 0, 0, 5 },
        { 0, 2, 0, 5 },
        { 0, 0, 2, 5 },
    }
}
-- set the array of transformations in the scatter node
scatter:setAttribute(octane.A_TRANSFORMS, transforms)
cheers,
Thomas
 
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 8:10 pm
				by stratified
				Hi there,
Here's something more complete. This script will reload the file in each scatter node. For the interested users, there's a generic update function here which will call a predicate function on each node of a specific type in the project. This might come in handy in other scripts.
Code: Select all
-- Calls the predicate function on each item of the given type.
-- This will recursive in each graph to find nodes of the given type.
--
-- @param   graph (Graph)
-- @param   nodeType (Type of node we're looking for)
-- @param   pred (Predicate function that takes a scatter node)
function updateItem(g, nodeType, pred)
    for i, item in ipairs(g:getOwnedItems()) do
        if item:getProperties().type == nodeType then
            pred(item)
        elseif item:getProperties().isGraph then
            updateItem(item, nodeType, pred)
        end
    end
end
-- reloads a scatter node
function reloadScatter(node)
    print("reloading ", node)
    node:setAttribute(octane.A_RELOAD, true)
end
updateItem(octane.nodegraph.getRootGraph(), octane.NT_GEO_SCATTER, reloadScatter)
cheers,
Thomas
 
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 8:22 pm
				by phdubrov
				getSelection() is really needed.
Will be another ways to run scripts not from menu only? Non-modal windows, additional buttons, shortcuts...
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 8:35 pm
				by stratified
				getSelection() (and other selection stuff) will be there in the next release candidate (1.23)
What do you mean by other ways? You can run a script from the command line as well (octane.exe --script myscript.lua) if you want to fully integrate Octane in some other tools.
Non-modal windows might be there in Octane 2.x but not for this 1.5 release. We need to think about this a bit more because with non-modal windows you could actually modify a lot of stuff in the standalone while your script is running (and make Octane crash). That's why the GUI is fully blocked while running a script.
not sure what you mean with additional buttons & shortcuts, could you elaborate a bit.
cheers,
Thomas
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 9:04 pm
				by phdubrov
				I just want a way to run scripts fast. For me the best solution would be a keyboard shortcuts or one shortcut to open window with scripts list.
Buttons mean buttons for toolbars, shortcuts - keyboard shortcuts.
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Thu Dec 19, 2013 9:26 pm
				by stratified
				okay, I understand we'll put something on our TODO list to assign shortcuts to scripts.
cheers,
Thomas
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Fri Dec 20, 2013 12:39 pm
				by manalokos
				Hello Thomas
This is great! Thank you!
Maybe even being able to assign custom buttons to scripts would be a good idea.
Kind regards
Filipe
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Fri Dec 20, 2013 8:52 pm
				by stratified
				We're going to try and come up with a solution that fits more nicely in the workflow in one of the next releases.
cheers,
Thomas
			 
			
					
				Re: Script request to refresh scatter nodes
				Posted: Sat Dec 21, 2013 4:16 am
				by Tugpsx
				What is this scripting thing!  
 
Why is it catching fire even with the non-programmers  
 
Why is it making this thing called Octane popular  
 
To find these answers, we will need to scan through these pages to discover the hidden treasures.  
