Hey guys, I’m new to 3dsmax scripting, basically
-
- List item
what am I trying to do is find a folder, then use the folder’s address to create a new material in the slate material editor, here I just combine two scripts that’ somebody else’s done, but I just can’t make it work, can somebody help me out?
here’s the script:
global BL_Import_Counter = 0 – need for renaming imported objects!
– ( don’t worry, its removed then the dialog is closed
)
fn RenameImported =
(
local HWND = DialogMonitorOPS.GetWindowHandle()
if ((UIAccessor.GetWindowText HWND) == “Import Name Conflict”) do
(
::BL_Import_Counter += 1
local oName = “_” + (formattedPrint ::BL_Import_Counter format:“4.4d”)
local cWND = UIAccessor.GetChildWindows HWND
for cw in cWND where cw != 0 and (UIAccessor.GetWindowClassName cw) == “Edit” do
(UIAccessor.SetWindowText cw (UIAccessor.GetWindowText cw + oName))
UIAccessor.sendMessageID HWND #IDOK
)
true
)
if classOf ro_BatchLoad == RolloutClass do destroyDialog ro_BatchLoad
rollout ro_BatchLoad “JPGLoader”
(
local listFiles = #(), recentDir = #(), iniFile
fn isDirectory str = (doesFileExist str and getFileAttribute str #directory)
button btn_directory "..." align:#left across:2
edittext etx_LastPath "" bold:true readOnly:true pos:[40,8] fieldWidth:(ro_BatchLoad.width-60)
spinner spn_Histrory "History #: " range:[1,100,5] type:#integer fieldWidth:40 pos:[345,30]
dropdownlist ddl_LastPath "Recent Directories:" items:#() pos:[12,30]
progressBar pgb_load
button btn_go "GO" pos:[10,108] width:440 height:16
multilistbox mlb_files "" height:15 width:435 pos:[12,130]
on ro_BatchLoad open do (
local me = getSourceFileName() -- Max9+
dir = getFilenamePath me
iniFile = dir + "BatchLoader.ini" -- save INI to the MS file location
if (doesFileExist iniFile) then (
LP = getINISetting iniFile "Saved" "LastPaths"
if LP != "" do (
recentDir = filterString LP ","
ddl_LastPath.items = recentDir
)
RS = getINISetting iniFile "Saved" "RecSave"
if RS != "" do spn_Histrory.value = (RS as integer)
)
else (
setINISetting iniFile "Saved" "LastPaths" ""
setINISetting iniFile "Saved" "RecSave" "5"
)
if ddl_LastPath.items.count > 0 then (
etx_LastPath.text = ddl_LastPath.selected
ddl_LastPath.enabled = true
)
else ddl_LastPath.enabled = false
)
on ro_BatchLoad close do (
setINISetting iniFile "Saved" "RecSave" (spn_Histrory.value as string)
if recentDir.count > spn_Histrory.value do (
while recentDir.count > spn_Histrory.value do deleteItem recentDir 1
)
local str = ""
for i in recentDir do append str (i + ",")
setINISetting iniFile "Saved" "LastPaths" str
-- remove the temp counter variable from the global space:
if globalVars.isglobal #BL_Import_Counter do globalVars.remove #BL_Import_Counter
)
on ddl_LastPath selected i do (
etx_LastPath.text = ddl_LastPath.items[i]
case rbt_LType.state of (
1: listFiles = getFiles (ddl_LastPath.items[i] + "/*.max")
2: listFiles = getFiles (ddl_LastPath.items[i] + "/*.*")
)
mlb_files.items = for f in listFiles collect (filenameFromPath f)
)
on btn_directory pressed do (
local selDir = etx_LastPath.text
local intDir = (if isDirectory selDir then selDir else (GetDir #import))
if (dir = getSavePath caption:"Select the directory" initialDir:intDir) != undefined do (
etx_LastPath.text = dir
ddl_LastPath.enabled = true
if findItem recentDir dir == 0 do
(
append recentDir dir
ddl_LastPath.items = recentDir
)
ddl_LastPath.selection = findItem recentDir dir
case rbt_LType.state of (
1: listFiles = getFiles (dir+"/*.max")
2: listFiles = getFiles (dir+"/*.*")
)
mlb_files.items = for f in listFiles collect (filenameFromPath f)
)
)
on rbt_LType changed state do (
if etx_LastPath.text != "" do (
case state of (
1: listFiles = getFiles (etx_LastPath.text+"/*.max")
2: listFiles = getFiles (etx_LastPath.text+"/*.*")
)
)
mlb_files.items = for f in listFiles collect (filenameFromPath f)
)
on btn_go pressed do (
fn LoadJPG dir = (
files = getFiles dir
x = 0
y = 0
sme_view = sme.GetView 1 -- get first view
for file in files do (
bm = openBitMap file
bmt = bitmapTexture()
bmt.bitmap = bm
sm = PhysicalMaterial()
sm.baseColorMap = bmt
filename = getFilenameFile file
sm.name = filename
bmt.name = filename e
print filename
n = getNodeByName filename
print n
n.material = sm
showTextureMap n.material on
sme_view.CreateNode n.material [x,y]
x = x += 500
)
)
LoadJPG "etx_LastPath"
)
)
createDialog ro_BatchLoad 460 340
style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox, #style_maximizebox, #style_resizing)