Finding all render targets

Forums: Finding all render targets
Forum for OctaneRender Lua scripting examples, discussion and support.

Finding all render targets

Postby grimm » Tue Dec 24, 2013 1:26 am

grimm Tue Dec 24, 2013 1:26 am
I can't get this to work right, doing something wrong for sure. :)

local renderTargets = octane.nodegraph.getRootGraph():findNodes(octane.NT_RENDERTARGET)

I would like to get a table back that holds all of the render target nodes in the root graph. Thanks,
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1324
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Finding all render targets

Postby roeland » Tue Dec 24, 2013 1:43 am

roeland Tue Dec 24, 2013 1:43 am
Your line of code is correct, it should work.

This is how you collect all node names into a new array, and then print all elements of the array. This array can be used for the items property of a combo box.

Code: Select all
local renderTargets = octane.nodegraph.getRootGraph():findNodes(octane.NT_RENDERTARGET)

-- the hash operator gives the length of the array (which is actually a table with integer keys)
print(#renderTargets)

names = {}

-- ipairs() returns an iterator object, which returns the integer keys and associated values in the array.
for i, rt in ipairs(renderTargets)
do
    names[#names + 1] = rt:getProperties().name   -- In an array the keys start at 1
end

for i, n in ipairs(names)
do
    print(n)
end


--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1811
Joined: Wed Mar 09, 2011 10:09 pm

Re: Finding all render targets

Postby grimm » Tue Dec 24, 2013 1:52 am

grimm Tue Dec 24, 2013 1:52 am
Ah, I see, thanks Roeland. :lol: I was using the ipairs backwards when i was building the table. :oops:
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1324
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Finding all render targets

Postby grimm » Tue Dec 24, 2013 1:56 am

grimm Tue Dec 24, 2013 1:56 am
Just another question about the code you wrote:

Do you have to do names[#names + 1] or can you just do names[i] ?
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1324
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Finding all render targets

Postby roeland » Tue Dec 24, 2013 2:01 am

roeland Tue Dec 24, 2013 2:01 am
In this case you can just use names[i].

The background is as follows: an array is a lua table with integer keys, starting from 1. So a three element array looks like this:
Code: Select all
t[1] = "a"
t[2] = "b"
t[3] = "c"


Now if you leave a gap like this, a lot of code will stop working:
Code: Select all
[code]
t[1] = "a"
t[2] = "b"
-- key 3 is not defined.
t[4] = "d"

Things like #t and ipairs(t) may assume there are only 2 elements in the array. Using t[#t + 1] makes sure you always insert with the next available key.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1811
Joined: Wed Mar 09, 2011 10:09 pm

Re: Finding all render targets

Postby grimm » Tue Dec 24, 2013 2:22 am

grimm Tue Dec 24, 2013 2:22 am
Cool, that makes sense. Thanks. I program in Ruby for my real job so I'm familiar with hashes which appear to be very similar to Lua tables. It's going to take some time to understand when I should be building an array table or a key/value pair table. What is used mostly for Octane's API?
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1324
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Finding all render targets

Postby roeland » Fri Dec 27, 2013 12:13 am

roeland Fri Dec 27, 2013 12:13 am
Both forms are used. If we need a list then it will be a table with integer keys. For properties we use a table with string keys. In this case the API doc will reference one of the items you can find under "Properties", where you can find the meaning of all the keys used.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1811
Joined: Wed Mar 09, 2011 10:09 pm

Re: Finding all render targets

Postby grimm » Sat Dec 28, 2013 9:20 pm

grimm Sat Dec 28, 2013 9:20 pm
I'm having another problem, this time with the combo box component. I can't set the default selected item in the drop down list. I'm trying to set it with this line of code:

Code: Select all
renderTargetDropDown:updateProperties { items = RENDER_TARGETS, selectedItem = RENDER_TARGETS[1] }


RENDER_TARGETS is the array of item, and they do show up in the drop down. What do you set the selectedItem to in order to set it? In the API docs it does say that this property is writable so it should be possible to set it, is that right? Thanks,
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1324
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Finding all render targets

Postby stratified » Sat Dec 28, 2013 10:06 pm

stratified Sat Dec 28, 2013 10:06 pm
grimm wrote:Just another question about the code you wrote:

Do you have to do names[#names + 1] or can you just do names[i] ?


Just for completeness, you can write this a little bit more explicit: table.insert(names, rt:getProperties().name). For more info see http://www.lua.org/manual/5.1/manual.html#pdf-table.insert.

cheers,
Thomas
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Finding all render targets

Postby stratified » Sat Dec 28, 2013 10:08 pm

stratified Sat Dec 28, 2013 10:08 pm
grimm wrote:I'm having another problem, this time with the combo box component. I can't set the default selected item in the drop down list. I'm trying to set it with this line of code:

Code: Select all
renderTargetDropDown:updateProperties { items = RENDER_TARGETS, selectedItem = RENDER_TARGETS[1] }


RENDER_TARGETS is the array of item, and they do show up in the drop down. What do you set the selectedItem to in order to set it? In the API docs it does say that this property is writable so it should be possible to set it, is that right? Thanks,


Hi grimm,

You're code is fine. It's a bug in the API. We'll fix this in the next release.

cheers,
Thomas
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand
Next

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 2 guests

Mon Jun 03, 2024 9:47 pm [ UTC ]