[Closed] Dynamic Button with Dynamic Images
hiho fellas,
i got a problem with making a little texturebrowser.
i’m trying to create dynamic buttons…np with dynamic images…prob.
i can also acces the buttons without problem but i can’t manage to get a dynamic rendermap into the .images[1]. and i thought before i bash my head in the desk i gonna ask here
try(closeRolloutFloater TexRO)catch()
sleep 0.1
rfTest = rolloutCreator "rfTestN" "rfTestC"
-- Start creating the rollout
rfTest.begin()
xOr=0
for i in $.material where i.diffusemap != undefined do (
xOr=xOr+1
local LoR=(("X" + xOr as string)as name)
rfTest.addControl #button LoR i.name paramStr:"align:#left width:110 height:110 enabled:false"-- add a button
-- rfTest.addHandler LoR #pressed filter:on codeStr:"MessageBox @Look to the \@Light\@ thing@"
)
rfTest.end()
TexRO = newRolloutFloater "Informator" 150 300
addRollout rfTest.def TexRO
XoR=0
for i in $.material where i.diffusemap != undefined do (
XoR=XoR+1
local lOr=("X" + XoR as string)
a= stringStream ""
format ("rfTestN."+lOr+".images=#(") to:a
-- format " \"IN_polypimp\\img\\SM_map.png\" " to:a
local rM= ((renderMap i.diffusemap filter:true size:[110,110] filename:"test.bmp" display:true)as string)
--format rM.name to:a
--#( renderMap CurSelection.material.materialList[2].diffusemap filter:true size:[110,110], "", 1, 1, 1, 1, 1)
format ", undefined, 1, 1, 1, 1, 1)" to:a
print a
-- (execute(a as string))
--rfTestN.X2.images=#("IN_polypimp\\img\\SM_map.png", undefined, 1, 1, 1, 1, 1)
)
i also tried just assigning the rM but that didn’t work as the 1lineNotation didn’t… help
edit: i noted it after the Rollout cuz i need to update it on selection change and that wouldn’t be possible when i just put it into the buttonCreation itSelf
pretty sure you’re going down the wrong path a bit here, but…
In the script ‘as posted’, there’s a few problems – it looks like you may have copy/pasted from the code while you were working on it? I see that you commented out the line that would include the RM bitmap (file)name into the images array… that should be in. Next up, you need to actually call ‘save RM’ for it to actually be saved to the drive (just specifying filename: in the renderMap call merely pre-assigns the filename, it doesn’t save it) for images: to take it as a bitmap filename, -and- you need to save it in a location from where it can be loaded e.g. #images, or #temp or so.
e.g. (select 1 object with a standard material with a diffuse map)
try(closeRolloutFloater TexRO)catch()
rfTest = rolloutCreator "rfTestN" "rfTestC"
rfTest.begin()
rfTest.addControl #button "mybutton" $.name paramStr:"align:#left width:110 height:110"
rfTest.end()
TexRO = newRolloutFloater "Informator" 150 300
addRollout rfTest.def TexRO
a= stringStream ""
format ("rfTestN.myButton.images=#(") to:a
rM= (renderMap $.material.diffusemap filter:true size:[110,110] filename:"$temp\ est.bmp" display:true)
save rM
format "@\"%\"" rM.filename to:a
format ", undefined, 1, 1, 1, 1, 1)" to:a
execute (a as string)
However, as I said, I think that you’re going down the wrong path in saving those images – unless you actually want them to be saved.
I would recommend keeping an array (empty at first) where you add the result of renderMap to the array. That means the bitmap values will remain available ‘as is’, at least until the array in which they are is destroyed. You can then reference those images in the images: assignment directly, without having had to save the bitmaps and all the problems that comes with that.
So, going back to some dynamic code (the code you pasted doesn’t evaluate, I’m afraid) still using rolloutCreator and such:
if (classOf myRolloutFloater == RolloutFloater) then ( closeRolloutFloater myRolloutFloater )
btnImagesArray = #()
myRollout = rolloutCreator "rfTestN" "rfTestC"
myRollout.begin()
curSel = getCurrentSelection()
for i = 1 to curSel.count do (
local o = curSel[i]
if ((classOf o.material == Standardmaterial) AND (o.material.diffusemap != undefined)) then (
btnStr = ("btn_" + i as string)
btnImagesArray[i] = renderMap o.material.diffuseMap filter:true size:[110,110] display:false
myRollout.addControl #button btnStr o.name paramStr:("align:#left width:110 height:110 images:#(btnImagesArray[" + i as string + "],undefined,1,1,1,1,1)")
myRollout.addHandler btnStr #pressed filter:true codeStr:("try ( " + btnStr + ".images = #(renderMap $.material.diffuseMap filter:true size:[110,110] display:false,undefined,1,1,1,1,1)); catch()")
)
)
myRollout.end()
myRolloutFloater = newRolloutFloater "Informator" 150 300
addRollout myRollout.def myRolloutFloater
Still pretty messy – I’m not a big fan of RolloutCreator so I’m not too familiar with how I might inline the array without breaking the build-up, for example, but the above code should work.
What it currently does is not quite so useful, but maybe you can figure out how to take the changes and apply them to what you’re doing
thats great thx man, here is the new code :bounce:
btnImagesArray = #()
rfTest = rolloutCreator "rfTestN" "rfTestC"
-- Start creating the rollout
rfTest.begin()
xOr=0
for i in $.material where i.diffusemap != undefined do (
xOr=xOr+1
local LoR=(("X" + xOr as string)as name)
btnImagesArray[(xOr as Integer)] = (renderMap i.diffusemap filter:true size:[110,110])
rfTest.addControl #button LoR i.name paramStr:("align:#left width:110 height:110 enabled:false images:#(btnImagesArray[" + (xOr as String) + "] , undefined, 1, 1, 1, 1, 1)")-- add a button
-- rfTest.addHandler LoR #pressed filter:on codeStr:"MessageBox @Look to the \@Light\@ thing@"
)
rfTest.end()
TexRO = newRolloutFloater "Informator" 150 300
addRollout rfTest.def TexRO