Message 1 of 4
Populating pop up window button with .mat file content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create a pop up window with buttons that will be populated with the name of an extracted .mat file that contains different materials. The idea is to use this pop up window as a quick way to apply textures within the viewport without going back to the SME by directly loading my standard .mat library that I use for all my projects.
Anyway, I keep getting some basic syntax error and I can't for the life of me find where the thing is going wrong. The script is not complete yet (as in I'll need to add a few things for it to do exactly what I need), but it's already breaking at the current step.
Below is the code :
try (destroyDialog materialButtonsDialog) catch()
rollout materialButtonsDialog "Material Library" width:350 height:640
(
local buttons = #()
-- Function to create buttons dynamically based on material names
fn createButtons materialNames =
(
local posX = 10
local posY = 30
local buttonWidth = 320
local buttonHeight = 25
local margin = 5
for i = 1 to materialNames.count do
(
local btnName = "btn_" + i as string
local btn = button btnName text:materialNames[i] pos:[posX, posY] width:buttonWidth height:buttonHeight
posY += buttonHeight + margin -- Increment position for the next button
append buttons btn -- Add button to the array
-- Add a simple event to demonstrate functionality
on btn pressed do
(
messageBox ("Material selected: " + btn.text)
)
)
)
-- Function to load materials from a .mat file and return their names
fn loadMaterialNamesFromMatFile =
(
local filename = getOpenFileName caption:"Select Material Library" types:"Material Library (*.mat)|*.mat"
local materialNames = #()
if filename != undefined then
(
local myLibrary = loadTempMaterialLibrary filename
if classOf myLibrary == MaterialLibrary then
(
for mat in myLibrary do
(
if mat != undefined then
(
append materialNames mat.name
)
)
)
else
(
messageBox "Failed to load the selected .mat file as a Material Library."
)
)
else
(
messageBox "No file was selected. Please select a valid .mat file."
)
return materialNames
)
-- Event to load materials and create buttons when the rollout opens
on materialButtonsDialog open do
(
local materialNames = loadMaterialNamesFromMatFile()
if materialNames.count > 0 then
(
createButtons materialNames
)
else
(
messageBox "No materials found in the selected .mat file."
)
)
button btnClose "Close" pos:[10, 610] width:330 height:25
on btnClose pressed do
(
destroyDialog materialButtonsDialog
)
)
createDialog materialButtonsDialog 350 640 resizable:false
If anybody has any idea on how to fix it, or do it differently, that would be greatly appreciated!
Thanks
Simon