Share

Script26_MeshColors.lua

Dialog = application:createdialog()
Dialog.caption = "Change display color"
Dialog.translatecaption = false

SettingsMesh = Dialog:adddropdown()
SettingsMesh.caption = "Selected mesh"
SettingsMesh.captionwidth = 120
SettingsMesh.translate = false

Tray = netfabbtrayhandler:gettray(0)

for i = 0, Tray.root.meshcount - 1 do
    local Traymesh = Tray.root:getmesh(i)
    SettingsMesh:additem(Traymesh.name, i, i, false)
end

SettingsMesh.onchange = "mesh_selected"

SettingsColor = Dialog:adddropdown()
SettingsColor.caption = "New color"
SettingsColor.captionwidth = 120
SettingsColor.translate = false

SettingsColor:additem("$FF0000", 0, 0, false)
SettingsColor:additem("$00FF00", 1, 1, false)
SettingsColor:additem("$0000FF", 2, 2, false)
SettingsColor:additem("$FFFF00", 3, 3, false)
SettingsColor:additem("$FF00FF", 4, 4, false)
SettingsColor:additem("$00FFFF", 5, 5, false)
SettingsColor:additem("$FFFFFF", 6, 6, false)
SettingsColor:additem("$000000", 7, 7, false)

ButtonColor = Dialog:addbutton()
ButtonColor.caption = "Apply color"
ButtonColor.translate = false
ButtonColor.onclick = "apply_color"

ShowColorTexture = Dialog:addcheckbox()
ShowColorTexture.caption = "Show color and texture"
ShowColorTexture.translate = false
ShowColorTexture.onclick = "showcolortexture"
ShowColorTexture.checked = application.showcolortexture

function close_form()
    Dialog:close(true)
end

function showcolortexture()
    application.showcolortexture = ShowColorTexture.checked
end

function mesh_selected()
    local Selected = SettingsMesh.selectedindex
    local Name = SettingsMesh:getitemtext(Selected)

    for i = 0, Tray.root.meshcount - 1 do
        local Traymesh = Tray.root:getmesh(i)
        if Traymesh.name == Name then
            Traymesh.selected = true
            return
        end
    end
end

function apply_color()
    local Selected = SettingsMesh.selectedindex
    local Name = SettingsMesh:getitemtext(Selected)
    local ColorMesh = nil

    for i = 0, Tray.root.meshcount - 1 do
        local Traymesh = Tray.root:getmesh(i)
        if Traymesh.name == Name then
            ColorMesh = Traymesh
        end
    end

    if ColorMesh ~= nil then
        local ColorIndex = SettingsColor.selectedindex
        local Color = SettingsColor:getitemtext(ColorIndex)

        if Color ~= "" then
            Color = string.sub(Color, 2)
            ColorMesh.color = Color
            application:triggerdesktopevent("updateparts")
        end
    else
        system:messagedlg("Selected mesh not found.")
    end
end

ButtonClose = Dialog:addbutton()
ButtonClose.caption = "Close form"
ButtonClose.translate = false
ButtonClose.onclick = "close_form"

Dialog:show()

Was this information helpful?