Script41_3mfDocumentation.lua
This example uses the Microsoft PowerPoint document Demo3mf.pptm included in the *
-- Lua example for Autodesk Netfabb 2022.0
-- The script shows the usage of external programs
-- Requires Microsoft Powerpoint installed and the path to the executable adjusted if necessary
system:setloggingtooglwindow(true)
saveFileDir = application:getappdatadirectory()
saveFileDir = saveFileDir .. "\\Netfabb\\Report3mf"
application:createfolder(saveFileDir)
insertMeshesIntoTable = function(meshgroup, Outtable)
for mesh_index = 0, meshgroup.meshcount - 1 do
local traymesh = meshgroup:getmesh(mesh_index)
table.insert(Outtable, traymesh)
end
for group_index = 0, meshgroup.groupcount - 1 do
subgroup = meshgroup:getsubgroup(group_index)
insertMeshesIntoTable(subgroup, Outtable)
end
end
-- Get root meshgroup from tray
root = tray.root
-- Collect meshes in the tray
meshes = {}
insertMeshesIntoTable(root, meshes)
-- Iterate over meshes in tray
for i, traymesh in pairs(meshes) do
local luamesh = traymesh.mesh
luamesh:applymatrix(traymesh.matrix)
-- export mesh file to output folder
--local meshname = saveFileDir .. "\\" .. "file" .. tostring(i) .. ".3mf"
--luamesh:saveto3mf(meshname)
luamesh:saveto3mf(string.format("%s\\file%i.3mf", saveFileDir, i))
-- export properties as text file to output folder
statsreport = system:createtextfile()
statsreport:writeline("Name: " .. traymesh.name)
statsreport:writeline("Face count: " .. luamesh.facecount)
local boundingbox = traymesh:calcoutbox()
statsreport:writeline("Height: " .. boundingbox.maxz - boundingbox.minz .. " mm")
if (luamesh.isok) then -- isok = ismanifold is true and isoriented is true and volume is positive
statsreport:writeline("Mesh is OK")
else
statsreport:writeline("Mesh is not OK")
end
--statsreport:savetofile(saveFileDir .. "\\" .. "file" .. tostring(i) .. ".txt")
statsreport:savetofile(string.format("%s\\file%i.txt", saveFileDir, i))
end
-- copy empty presentation to output folder
pathPptm = saveFileDir .. "\\Demo3mf.pptm"
cmdstringcopy = '/c copy ".\\Examples\\Lua Scripts\\Demo3mf.pptm" ' .. saveFileDir .. '"'
system:shellexecute("cmd", cmdstringcopy, true, true)
-- launch PowerPoint with copied presentation file and run embedded 'main' macro which imports 3D and text files, generating new slides as needed
cmdstring = '/c powerpnt /M "' .. pathPptm .. '" main'
system:shellexecute("cmd", cmdstring, true, true, "C:\\Program Files\\Microsoft Office\\root\\Office16")