Page 1 of 2
Finding all render targets
Posted: Tue Dec 24, 2013 1:26 am
by grimm
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,
Re: Finding all render targets
Posted: Tue Dec 24, 2013 1:43 am
by roeland
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
Re: Finding all render targets
Posted: Tue Dec 24, 2013 1:52 am
by grimm
Ah, I see, thanks Roeland.

I was using the ipairs backwards when i was building the table.

Re: Finding all render targets
Posted: Tue Dec 24, 2013 1:56 am
by grimm
Just another question about the code you wrote:
Do you have to do names[#names + 1] or can you just do names ?
Re: Finding all render targets
Posted: Tue Dec 24, 2013 2:01 am
by roeland
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:
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
Re: Finding all render targets
Posted: Tue Dec 24, 2013 2:22 am
by grimm
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?
Re: Finding all render targets
Posted: Fri Dec 27, 2013 12:13 am
by roeland
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
Re: Finding all render targets
Posted: Sat Dec 28, 2013 9:20 pm
by grimm
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,
Re: Finding all render targets
Posted: Sat Dec 28, 2013 10:06 pm
by stratified
grimm wrote:Just another question about the code you wrote:
Do you have to do names[#names + 1] or can you just do names ?
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.ht ... ble.insert.
cheers,
Thomas
Re: Finding all render targets
Posted: Sat Dec 28, 2013 10:08 pm
by stratified
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