Getting the path to a texture image file from material nodes

Forum for OctaneRender Lua scripting examples, discussion and support.
Post Reply
User avatar
MB
Licensed Customer
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.
Contact:

All,

I have been unable to figure out how to get the paths to any texture image files used within a material.
I would like to get all image files a material might use, i.e. normal and bump maps as well as diffuse and specular. Could anyone enlighten me.

Many thanks

Mark
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
roeland
OctaneRender Team
Posts: 1823
Joined: Wed Mar 09, 2011 10:09 pm

You can recursively walk over all the input nodes of the given node:

Code: Select all

local function walk(node, list)
    -- recursive walk
    for i = 1,node:getPinCount() do
        local src = node:getInputNodeIx(i)
        if src ~= nil then walk(src, list) end
    end

    -- see if this node has a filename attribute
    local ok, value = pcall(node.getAttribute, node, "filename")
    if ok then
        table.insert(list, value)
    end
end

local list = {}
walk(octane.project.getSelection()[1], list)
for k, v in ipairs(list) do
    print(v)
end
To check if any node has a file name attribute, you can use pcall, a standard Lua function which calls another function (octane.node.getAttribute in our case) with the given arguments and catches any errors raised.

This code gives you the file names of any kind of file referenced by the nodes, not just image textures.

--
Roeland
User avatar
MB
Licensed Customer
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.
Contact:

Many Thanks Roeland
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
Post Reply

Return to “Lua Scripting”