Getting the path to a texture image file from material nodes

Forums: Getting the path to a texture image file from material nodes
Forum for OctaneRender Lua scripting examples, discussion and support.

Getting the path to a texture image file from material nodes

Postby MB » Mon May 23, 2016 6:44 pm

MB Mon May 23, 2016 6:44 pm
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
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Getting the path to a texture image file from material nodes

Postby roeland » Mon May 30, 2016 2:27 am

roeland Mon May 30, 2016 2:27 am
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
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1810
Joined: Wed Mar 09, 2011 10:09 pm

Re: Getting the path to a texture image file from material nodes

Postby MB » Wed Jun 01, 2016 9:51 pm

MB Wed Jun 01, 2016 9:51 pm
Many Thanks Roeland
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 8 guests

Thu Apr 18, 2024 11:14 am [ UTC ]