This is my first Lua script -- the tough part was figuring out how to get the attribute values of the Octane nodes. When you pass a string value as the name of an attribute it errors out. So I had to type in integers, one at a time, until I found the ones that were associated with "A_FILENAME" and "A_RELOAD". Crappy process, but hopefully the documentation on the API will improve.
Anyhow, it works without updating the mtl file. So have fun ZBrushers!
Here's the script :
- Code: Select all
function updateFileData(objFile)
local f = io.open(objFile, "r")
local fileData = f:read("*all")
f:close()
fileData = fileData:gsub("g (%w+)", "usemtl %1")
f = io.open(objFile, "w")
f:write(fileData)
f:close()
--print (fileData)
end
-- main function body
-- get the selected mesh
local selectedRt = octane.project.getSelection()[1]
if not selectedRt or selectedRt.type ~= octane.NT_GEO_MESH then
showError("no mesh selected")
return nil
end
--print (selectedRt)
-- get the file path for the mesh
local objFileName = octane.node.getAttribute( selectedRt , 29 )
--print (objFileName )
updateFileData(objFileName)
--reload mesh
octane.node.setAttribute(selectedRt, 94, true, true)