[Closed] asset browser
i found this piece of script somewhere on the web and i tried to run it on max9. unfortunatly it won’t do as expected. the problem far seems in the “button creation part” (marked red). it says, button1 is already existing. does anybody know, how to fix this?
as mentioned in earlier post, i’m a real scripting nobody
peace + TIA.
-- -------------------------------------------
-- Basic Asset Manager by Gavin Greenwalt --
-- -- Straightface Studios :| Seattle, WA ----
-- -------- version 2.0 kind of --------------
-- Just to be clear here is the directory structure it expects:
-- ...\LibraryPath\<Category Names>\filename.jpg&.max
--
Global AssetManager, ScenesDialog
Struct AssetManagerStruct (Categories=#(), Scenes=#())
Struct SceneStruct (ID, CategoryID, Name, Path, Thumbnail)
Struct CategoryStruct (ID, Name)
try(destroydialog AssetManagerDialog)catch()
AssetManager = AssetManagerStruct()
AssetManager.Categories = #(
-- Template Categories ---
CategoryStruct ID:1 Name:"Category Boats",
CategoryStruct ID:2 Name:"Category Cars"
-- End Template Categories --
)
AssetManager.Scenes = #(
-- Template Scenes ---
SceneStruct ID:1 CategoryID:1 Name:"Laser One" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg",
SceneStruct ID:1 CategoryID:1 Name:"Laser two" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg"
-- End Template Scenes --
)
Rollout AssetManagerDialog "Manage Your Assets" width:450 height:400
(
fn QuadifyString stringvar =
(
stringvar = filterstring stringvar "\\"
assembly = ""
for i =1 to stringvar.count - 1 do
(
append assembly (stringvar[i]+"\\\\\\\\")
)
append assembly stringvar[stringvar.count]
assembly
)
DropDownList CategoryDropDown "Categories:" across:2
Button CustomLibraryButton "Load New Library From Path" height:40 offset:[0,5]
subrollout ScenesSubrollout "Scenes" width:440 height:335
on AssetManagerDialog open do
(
CategoryDropDown.items = #("")
CategoryDropDown.items = (join CategoryDropDown.items (for o in AssetManager.Categories collect o.name))
)
on CustomLibraryButton pressed do
(
thumbnailtypes = #(".jpg",".tif",".png",".bmp")
newpath = getsavepath()
newcats = getdirectories (newpath+"\\*")
AssetManager.Categories = #()
AssetManager.Scenes = #()
for i = 1 to newcats.count do
(
catname = (filterstring newcats[i] "\\")
catname = catname[catname.count]
append AssetManager.Categories (CategoryStruct ID:i Name:catName)
scenes = getfiles (newcats[i]+"*")
maxfiles = (for o in scenes where (getfilenametype o == ".max") collect o)
thumbnails = (for o in scenes where (finditem thumbnailtypes (getfilenametype o)) != 0 collect o)
for o in maxfiles do
(
idval = (AssetManager.Scenes.count + 1)
scenename = getfilenamefile o
thumb = (for t in thumbnails where (matchpattern (getfilenamefile t) pattern:(getfilenamefile o)) collect t)[1]
append AssetManager.Scenes (SceneStruct ID:idval CategoryID:i Name:scenename path:o Thumbnail:thumb)
)
)
CategoryDropDown.items = #("")
CategoryDropDown.items = (join CategoryDropDown.items (for o in AssetManager.Categories collect o.name))
try(removeSubRollout AssetManagerDialog.ScenesSubRollout ScenesDialog)catch()
)
on CategoryDropDown selected s do
(
s -= 1
try(removeSubRollout AssetManagerDialog.ScenesSubRollout ScenesDialog)catch()
ScenesString = "" as stringstream
format "Rollout ScenesDialog \"Assets\" (
" to:ScenesString
scenes = for o in AssetManager.Scenes where o.CategoryID == s collect o
if (scenes).count != 0 then
(
for o in scenes do
(
format "Button Button% \"%\" images:#(\"%\", undefined, 1, 1, 1, 1, 1) width:100 height:100 align:#left across:4
" o.id o.name (QuadifyString o.thumbnail) to:ScenesString
)
for o in scenes do
(
format "on button% pressed do
" o.id to:ScenesString
format "(
" to: ScenesString
format "mergemaxfile \"%\" #Select
" (QuadifyString o.path) to: ScenesString
format ")
" to: ScenesString
)
)
else
(
format "label NoMapsLabel \"No Scenes Found\"" to:ScenesString
)
format ")" to:ScenesString
execute (ScenesString as string)
AddSubRollout AssetManagerDialog.ScenesSubRollout ScenesDialog
)
)
createdialog AssetManagerDialog
In your array definition… you have two ID:1’s
I’m assuming the ID variable should be unique!
SceneStruct ID:1 CategoryID:1 Name:"Laser One" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg",
SceneStruct ID:1 CategoryID:1 Name:"Laser two" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg"
try:
SceneStruct ID:1 CategoryID:1 Name:"Laser One" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg",
SceneStruct ID:[b]2[/b] CategoryID:1 Name:"Laser two" path:"Y:\lib\3D Objects\boat laser\laser.max" Thumbnail:"Y:\lib\3D Objects\boat laser\laser.jpg"
thanks to you kramsurfer – with your help it worked! i surely am the worst scripter on the planet and i am glad there are some many helpful souls out there.
If you know how to cut and paste… You’re ten steps ahead of the artist that doesn’t know how to open the listener window ! ! Just like learning an instrument, in a few years you’ll realize that you’re actually playing some decent music… just keep playing !