function readLines(sPath) local file = io.open(sPath, "r") local n1,n2,n3,n4,n5,n6,n7,n8,n9 local section_name,section_start,section_end local xfa_read=0 local file_read=0 if file then local tLines = {} local tline = {} for sline in file:lines() do file_name=sline:match('file :(.-[^\\]-([^%.]+))$') if file_name then print(file_name) file_read=file_read+1 table.insert(FILES,{file_name,xfa_read+1,0}) if file_read-1>0 then FILES[file_read-1][3]=xfa_read end else n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16 = sline:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") if n1 and n2 and n3 and n4 and n5 and n6 and n7 and n8 and n9 and n10 and n11 and n12 and n13 and n14 and n15 and n16 then xfa_read= xfa_read+1 table.insert(tLines,{{n1,n2,n3,n4},{n5,n6,n7,n8},{n9,n10,n11,n12}} ) end end end file.close() if file_read>0 then FILES[file_read][3]=xfa_read end XFA = tLines end return nil end function lengthTable(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end function importfiles() -- create the group node local transforms={} local MESHES={} local MATERIALS={} local items={} local parent = octane.nodegraph.create{ type = octane.GT_STANDARD, name = FILES[#FILES][1] } local group = octane.node.create{ type=octane.NT_GEO_GROUP, name="Group" ,graphOwner=parent} group:setAttribute(octane.A_PIN_COUNT, #FILES, true) -- create a node for each obj file and connect it to the group for i=1, #FILES do local mesh = octane.node.create{type=octane.NT_GEO_MESH , name=FILES[i][1] ,graphOwner=parent} mesh:setAttribute(octane.A_FILENAME, FILES[i][1], true) local scatter = octane.node.create{type=octane.NT_GEO_SCATTER ,graphOwner=parent} transforms={} for j=FILES[i][2], FILES[i][3] do table.insert(transforms,XFA[j]) end scatter:setAttribute(octane.A_TRANSFORMS, transforms) scatter:connectToIx(1,mesh) group:connectToIx(i, scatter) table.insert(MESHES,mesh) end local pin for i=1, #MESHES do for pinIx=1,MESHES[i]:getPinCount() do pin=MESHES[i]:getPinInfoIx(pinIx) if MATERIALS[pin.label]==nil then MATERIALS[pin.label]={} end table.insert(MATERIALS[pin.label],{i,pinIx}) end end local mat for name,k in pairs(MATERIALS) do print(k) mat=octane.node.create{type=octane.NT_IN_MATERIAL, name=name,graphOwner=parent} for j=1,#k do MESHES[k[j][1]]:connectToIx(k[j][2], mat) end end meshout=octane.node.create{type=octane.NT_OUT_GEOMETRY, name="GEOM_OUT",graphOwner=parent} meshout:connectToIx(1, group) end -- Global vars XFA={} FILES={} local ret1 = octane.gui.showDialog { type = octane.gui.dialogType.FILE_DIALOG, title = "Choose instance export script", wildcards = "*.oscr", save = false, path = IN_PATH, } -- if a file is chosen if ret1.result ~= "" then IN_PATH = ret1.result readLines(IN_PATH ) importfiles() else IN_PATH = nil end